<commit_before><?php
/**
 * Functions used for edition help
 *
 * @author Anakeen 2003
 * @version $Id: FDL_external.php,v 1.71 2009/01/13 09:37:25 eric Exp $
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package FREEDOM
 * @subpackage 
 */
/**
 */

include_once("FDL/Class.Dir.php");
include_once("FDL/Lib.Dir.php");




function vault_filename($th, $fileid) {


  if (preg_match(PREGEXPFILE, $fileid, $reg)) {	 
    // reg[1] is mime type
      $vf = newFreeVaultFile($th->dbaccess);
    if ($vf -> Show ($reg[2], $info) == "") $fname = $info->name;
    else $fname=sprintf(_("file %d"),$th->initid);
  } else {
    $fname=sprintf(_("file %d"),$th->initid);
  }

  return array($fname);
}


/**
 * Functions used for edition help
 *
 * @param string $dbaccess database specification
 * @param int $docid identificator document 
 * @return array first item : the title
 */
function gettitle($dbaccess, $docid) {

  $doc=new_Doc($dbaccess, $docid);
  if ($doc->isAffected())  return array($doc->title);
  return array("?"," "); // suppress
}

/**
 * link enum definition from other def
 */
function linkenum($famid,$attrid) {
  
  $dbaccess=getParam("FREEDOM_DB");
  if (! is_numeric($famid)) $famid=getFamIdFromName($dbaccess,$famid);
  $soc = new_Doc($dbaccess, $famid);
  if ($soc->isAffected()) {
    $a = $soc->getAttribute($attrid);
    return $a->phpfunc;
  }
  return "";
}
// liste de personnes
function lmail( $dbaccess, $name) {     

  global $action;
  

  $filter=array();
  if ($name != "") {
    $name=pg_escape_string($name);
    $filter[]="(title ~* '$name') or (us_mail ~* '$name')";
  }

  $filter[] = "us_mail is not null";
  $famid=getFamIdFromName($dbaccess,"USER");

  $tinter = getChildDoc($dbaccess, 0,0,100, $filter,$action->user->id,"TABLE",$famid);
  
  $tr = array();

  while(list($k,$v) = each($tinter)) {
            
    $mail = getv($v,"us_mail");
    $usw=getv($v,"us_whatid");
    $uid="";
    if ($usw > 0) {
      $uid=$v["id"];
      $type="1";//$type="link";  // cause it is a bool
    } else {
      $type="0";//$type="plain";
      $uid=" ";
    }
    $tr[] = array($v["title"] ,$v["title"]." <$mail>",$uid,$type);
    
  }
  return $tr;  
}
function tplmail($dbaccess,$type,$famid,$wfamid,$name) {
  switch($type) {
  case 'F': // address fix
    return lmail($dbaccess,$name);
  case 'A': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'text',false,$name);
    return $ta;
  case 'D': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'docid',false,$name);
    return $ta;
  case 'G': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'file',false,$name);
    $ta = array_merge($ta,getFamAttribute($dbaccess,$famid,'image',false,$name));
    return $ta;
  case 'E': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'',true,$name);
    return $ta;
  case 'WA': // value of attribute
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'text',false,$name);
    return $ta;
  case 'WE': // value of attribute
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'',true,$name);
    return $ta;
  case 'WD': // value of attribute
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'docid',false,$name);
    return $ta;
  case 'PR':    
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'docid',true,$name);
    return $ta;
  case 'WPR':    
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'docid',true,$name);
    return $ta;
  case 'P':
    return getGlobalsParameters($name);
  }
  return "error tplmail($dbaccess,$type,$famid, $name)";
}
function tpluser($dbaccess,$type,$famid,$wfamid,$name) {
  switch($type) {
  case 'F': // address fix
    $users= lfamily($dbaccess,"IUSER",$name);
    if (is_array($users)) {
      foreach ($users as $k=>$v) {
	$users[$k][1]=$v[1].' ('.$v[2].')';
      }
    }
    return $users;
  default:
    return tplmail($dbaccess,$type,$famid,$wfamid,$name);
  }
}
function getGlobalsParameters($name) {
  include_once("Class.QueryDb.php");
  $q=new QueryDb("","ParamDef");

  $tr = array();
  $q->AddQuery("isglob = 'Y'");
  if ($name)  $q->AddQuery("name ~* '".pg_escape_string($name)."'");
  $q->order_by="name";
  $la=$q->Query(0,20,"TABLE");
  foreach ($la as $k=>$v) {
    $p=$v["name"].' ('.$v["descr"].')';
    $tr[] = array($p,$p);
  }
  return $tr;
}

/**
 * attribut list to be use in mail template
 */
function getFamAttribute($dbaccess, $famid, $type="text", $param=false, $name="") {  
  $doc = createDoc($dbaccess, $famid,false);  
  $tr = array();
  if ($param) $tinter=$doc->getParamAttributes();
  else  $tinter = $doc->GetNormalAttributes();  
  $name=strtolower($name);
  // HERE HERE HERE
  $pattern_name = preg_quote($name);
  $pattern_type = preg_quote($type);
  foreach($tinter as $k=>$v) {
    if (($name == "") ||    (preg_match("/$pattern_name/i", $v->getLabel() , $reg)) || (preg_match("/$pattern_name/", $v->id , $reg)))
      if (($type == "") || ($v->type==$type) || ((strpos($type,'|')>0) && (preg_match("/$pattern_type/", $v->type , $reg)))) {
	$r=$v->id. ' ('.$v->getLabel().')';
	$tr[] = array($r,$r);
      }
    
  }
  return $tr;  
}

// liste des familles
function lfamilies($dbaccess, $name='',$subfam="") {
  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
  global $action;
  
  if ($subfam=="") {
    $tinter = GetClassesDoc($dbaccess, $action->user->id,0,"TABLE");
  } else {
    if (! is_numeric($subfam)) $subfam=getFamIdFromName($dbaccess,$subfam);
    $cdoc = new_Doc($dbaccess,$subfam);
    $tinter = $cdoc->GetChildFam();
    $tinter[]=get_object_vars($cdoc);
  }
  
  $tr = array();

  $name=strtolower($name);
  // HERE HERE HERE
  $pattern_name = preg_quote($name);
  while(list($k,$v) = each($tinter)) {
    $ftitle=DocFam::getLangTitle($v);
    if (($name == "") || (preg_match("/$pattern_name/i", $ftitle , $reg))) {
<commit_msg>correct preg on getFamAttribute() (closes #865)<commit_after><?php
/**
 * Functions used for edition help
 *
 * @author Anakeen 2003
 * @version $Id: FDL_external.php,v 1.71 2009/01/13 09:37:25 eric Exp $
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package FREEDOM
 * @subpackage 
 */
/**
 */

include_once("FDL/Class.Dir.php");
include_once("FDL/Lib.Dir.php");




function vault_filename($th, $fileid) {


  if (preg_match(PREGEXPFILE, $fileid, $reg)) {	 
    // reg[1] is mime type
      $vf = newFreeVaultFile($th->dbaccess);
    if ($vf -> Show ($reg[2], $info) == "") $fname = $info->name;
    else $fname=sprintf(_("file %d"),$th->initid);
  } else {
    $fname=sprintf(_("file %d"),$th->initid);
  }

  return array($fname);
}


/**
 * Functions used for edition help
 *
 * @param string $dbaccess database specification
 * @param int $docid identificator document 
 * @return array first item : the title
 */
function gettitle($dbaccess, $docid) {

  $doc=new_Doc($dbaccess, $docid);
  if ($doc->isAffected())  return array($doc->title);
  return array("?"," "); // suppress
}

/**
 * link enum definition from other def
 */
function linkenum($famid,$attrid) {
  
  $dbaccess=getParam("FREEDOM_DB");
  if (! is_numeric($famid)) $famid=getFamIdFromName($dbaccess,$famid);
  $soc = new_Doc($dbaccess, $famid);
  if ($soc->isAffected()) {
    $a = $soc->getAttribute($attrid);
    return $a->phpfunc;
  }
  return "";
}
// liste de personnes
function lmail( $dbaccess, $name) {     

  global $action;
  

  $filter=array();
  if ($name != "") {
    $name=pg_escape_string($name);
    $filter[]="(title ~* '$name') or (us_mail ~* '$name')";
  }

  $filter[] = "us_mail is not null";
  $famid=getFamIdFromName($dbaccess,"USER");

  $tinter = getChildDoc($dbaccess, 0,0,100, $filter,$action->user->id,"TABLE",$famid);
  
  $tr = array();

  while(list($k,$v) = each($tinter)) {
            
    $mail = getv($v,"us_mail");
    $usw=getv($v,"us_whatid");
    $uid="";
    if ($usw > 0) {
      $uid=$v["id"];
      $type="1";//$type="link";  // cause it is a bool
    } else {
      $type="0";//$type="plain";
      $uid=" ";
    }
    $tr[] = array($v["title"] ,$v["title"]." <$mail>",$uid,$type);
    
  }
  return $tr;  
}
function tplmail($dbaccess,$type,$famid,$wfamid,$name) {
  switch($type) {
  case 'F': // address fix
    return lmail($dbaccess,$name);
  case 'A': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'text',false,$name);
    return $ta;
  case 'D': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'docid',false,$name);
    return $ta;
  case 'G': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'file',false,$name);
    $ta = array_merge($ta,getFamAttribute($dbaccess,$famid,'image',false,$name));
    return $ta;
  case 'E': // value of attribute
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'',true,$name);
    return $ta;
  case 'WA': // value of attribute
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'text',false,$name);
    return $ta;
  case 'WE': // value of attribute
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'',true,$name);
    return $ta;
  case 'WD': // value of attribute
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'docid',false,$name);
    return $ta;
  case 'PR':    
    if (! $famid) return _("family must be defined");
    $ta=getFamAttribute($dbaccess,$famid,'docid',true,$name);
    return $ta;
  case 'WPR':    
    if (! $wfamid) return _("cycle family must be defined");
    $ta=getFamAttribute($dbaccess,$wfamid,'docid',true,$name);
    return $ta;
  case 'P':
    return getGlobalsParameters($name);
  }
  return "error tplmail($dbaccess,$type,$famid, $name)";
}
function tpluser($dbaccess,$type,$famid,$wfamid,$name) {
  switch($type) {
  case 'F': // address fix
    $users= lfamily($dbaccess,"IUSER",$name);
    if (is_array($users)) {
      foreach ($users as $k=>$v) {
	$users[$k][1]=$v[1].' ('.$v[2].')';
      }
    }
    return $users;
  default:
    return tplmail($dbaccess,$type,$famid,$wfamid,$name);
  }
}
function getGlobalsParameters($name) {
  include_once("Class.QueryDb.php");
  $q=new QueryDb("","ParamDef");

  $tr = array();
  $q->AddQuery("isglob = 'Y'");
  if ($name)  $q->AddQuery("name ~* '".pg_escape_string($name)."'");
  $q->order_by="name";
  $la=$q->Query(0,20,"TABLE");
  foreach ($la as $k=>$v) {
    $p=$v["name"].' ('.$v["descr"].')';
    $tr[] = array($p,$p);
  }
  return $tr;
}

/**
 * attribut list to be use in mail template
 */
function getFamAttribute($dbaccess, $famid, $type="text", $param=false, $name="") {  
  $doc = createDoc($dbaccess, $famid,false);  
  $tr = array();
  if ($param) $tinter=$doc->getParamAttributes();
  else  $tinter = $doc->GetNormalAttributes();  
  $name=strtolower($name);
  // HERE HERE HERE
  $pattern_name = preg_quote($name);
  $pattern_type = ($type);
  foreach($tinter as $k=>$v) {
    if (($name == "") ||    (preg_match("/$pattern_name/i", $v->getLabel() , $reg)) || (preg_match("/$pattern_name/", $v->id , $reg))) {
        preg_match("/$pattern_type/", $v->type , $reg);
      if (($type == "") || ($v->type==$type) || ((strpos($type,'|')>0) && (preg_match("/$pattern_type/", $v->type , $reg)))) {
	$r=$v->id. ' ('.$v->getLabel().')';	
	$tr[] = array($r,$r);
      }
    }
  }
  return $tr;  
}

// liste des familles
function lfamilies($dbaccess, $name='',$subfam="") {
  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
  global $action;
  
  if ($subfam=="") {
    $tinter = GetClassesDoc($dbaccess, $action->user->id,0,"TABLE");
  } else {
    if (! is_numeric($subfam)) $subfam=getFamIdFromName($dbaccess,$subfam);
    $cdoc = new_Doc($dbaccess,$subfam);
    $tinter = $cdoc->GetChildFam();
    $tinter[]=get_object_vars($cdoc);
  }
  
  $tr = array();

  $name=strtolower($name);
  // HERE HERE HERE
  $pattern_name = preg_quote($name);
  while(list($k,$v) = each($tinter)) {
    $ftitle=DocFam::getLangTitle($v);
    if (($name == "") || (preg_match("/$pattern_name/i", $ftitle , $reg))) {

{'fraction_non_alphanumeric': 0.2200031328320802, 'fraction_numerical': 0.006657268170426065, 'mean_word_length': 3.8942123418934456, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2231099', 'n_tokens_mistral': 4956, 'n_tokens_neox': 4762, 'n_words': 932}