Simple Groupware PHP Cross Reference Groupware Applications

Source: /src/core/classes/trigger.php - 518 lines - 21436 bytes - Summary - Text - Print

   1  <?php
   2      /**************************************************************************\
   3      * Simple Groupware 0.743                                                   *
   4      * http://www.simple-groupware.de                                           *
   5      * Copyright (C) 2002-2012 by Thomas Bley                                   *
   6      * ------------------------------------------------------------------------ *
   7      *  This program is free software; you can redistribute it and/or           *
   8      *  modify it under the terms of the GNU General Public License Version 2   *
   9      *  as published by the Free Software Foundation; only version 2            *
  10      *  of the License, no later version.                                       *
  11      *                                                                          *
  12      *  This program is distributed in the hope that it will be useful,         *
  13      *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14      *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
  15      *  GNU General Public License for more details.                            *
  16      *                                                                          *
  17      *  You should have received a copy of the GNU General Public License       *
  18      *  Version 2 along with this program; if not, write to the Free Software   *
  19      *  Foundation, Inc., 59 Temple Place - Suite 330, Boston,                  *
  20      *  MA  02111-1307, USA.                                                    *
  21      \**************************************************************************/
  22  
  23  class trigger {
  24  
  25  static function login() {
  26    db_update("simple_sys_users",array("status"=>"online"),array("username=@username@","coalesce(status,'')!='ooo'"),array("username"=>$_SESSION["username"]));
  27    return "";
  28  }
  29  
  30  static function logout() {
  31    db_update("simple_sys_users",array("status"=>"offline"),array("username=@username@","coalesce(status,'')!='ooo'"),array("username"=>$_SESSION["username"]));
  32    return "";
  33  }
  34  
  35  // syntax: trigger_new="exec:cmd"
  36  // e.g. trigger_new="exec:echo @fieldname@ >/tmp/example.txt"
  37  static function exec($id, $data, $params) {
  38    $cmd = implode(":",$params);
  39    if (preg_match_all("|@(.*?)@|i",$cmd,$matches,PREG_SET_ORDER)) {
  40      foreach ($matches as $match) {
  41        if (count($match)!=2) continue;
  42        $req_key = $match[1];
  43        if (isset($data[$req_key])) {
  44          $cmd = str_replace("@".$req_key."@",escapeshellarg($data[$req_key]),$cmd);
  45    } } }
  46    if ($cmd=="") return "";
  47    sys_notification(sprintf("{t}System command executed: %s{/t}", $cmd));
  48    return sys_exec($cmd);
  49  }
  50  
  51  static function notify($id, $data, $params, $table) {
  52    db_notification_delete($table, $id);
  53    if (empty($data["notification"]) or folder_in_trash($data["folder"])) return "";
  54    if (class_exists("notify") and method_exists("notify", $table)) {
  55      return call_user_func(array("notify", $table), $id, $data, $params, $table);
  56    }
  57    return "";
  58  }
  59  
  60  static function duration($id, $data, $params, $table) {
  61    if ($data["ending"]==0 or $data["begin"]==0) return "";
  62    $duration = $data["ending"] - $data["begin"];
  63    if (!empty($params[0])) $duration += $params[0];
  64    if (!empty($data["pause"])) $duration -= ($data["pause"]*3600);
  65    db_update($table,array("duration"=>$duration),array("id=@id@"),array("id"=>$id));
  66    return "";
  67  }
  68  
  69  static function createedituser($id, $data) {
  70    if ($_SESSION["username"]==$data["username"]) login::process_login($data["username"]);
  71    return "";
  72  }
  73  
  74  static function createuser($id, $data) {
  75    $folder = SIMPLE_STORE."/home/".$data["username"]."/";
  76    if (!is_dir($folder)) {
  77      sys_mkdir($folder);
  78      sys_notification(sprintf("{t}Folder created.{/t} (%s)", $folder));
  79    }
  80    self::createedituser($id,$data);
  81    return "";
  82  }
  83  
  84  static function deleteuser($id, $data) {
  85    $count = db_select_value("simple_sys_users","count(*) as count","username=@username@",array("username"=>$data["username"]));
  86    $row_id = folder_from_path("^home_".$data["username"]);
  87    if (!empty($count) and !empty($row_id)) {
  88      folders::delete($row_id);
  89      db_update("simple_sys_groups",array("members"=>"replace(members,'|".sql_quote($data["username"])."|','|')"),array("members like @username@"),array("username"=>"%|".$data["username"]."|%"),array("quote"=>false));
  90      sys_notification(sprintf("{t}Folder structure moved to trash.{/t} (%s)", $data["username"]));
  91    }
  92    db_update("simple_sys_users",array("activated"=>"0"),array("id=@id@"),array("id"=>$id));
  93    // TODO trash home folder on local fs?
  94    return "";
  95  }
  96  
  97  static function increase_pwdexpire($id) {
  98    $expire = db_select_value("simple_sys_users","pwdexpires","id=@id@",array("id"=>$id));
  99    if (!empty($expire) and $expire < NOW) {
 100      $expires = NOW + 7776000; // 90 days
 101      db_update("simple_sys_users",array("pwdexpires"=>$expires),array("id=@id@"),array("id"=>$id));
 102    }
 103    return "";
 104  }
 105  
 106  static function deletegroup($id) {
 107    db_update("simple_sys_groups",array("activated"=>"0"),array("id=@id@"),array("id"=>$id));
 108    return "";
 109  }
 110  
 111  static function deletegroup_by_name($name) {
 112    db_update("simple_sys_groups",array("activated"=>"0"),array("groupname=@name@"),array("name"=>$name));
 113    sys_notification(sprintf("{t}Group deactivated.{/t} (%s)", $name));
 114    return "";
 115  }
 116  
 117  static function createeditforum($id) {
 118    db_update("simple_forum",array("threadid"=>$id),array("id=@id@","threadid=0"),array("id"=>$id));
 119    return "";
 120  }
 121  
 122  static function createeditcms($id, $data, $unused, $table) {
 123    db_update($table,array("lastmodified"=>"lastmodified+1"),array("data like @pagename@"),array("pagename"=>"%(:include ".$data["pagename"]."%"),array("quote"=>false,"no_defaults"=>1));
 124  
 125    $rows = db_select($table,"pagename",array("data like @content@","staticcache='1'"),"","",array("content"=>"%(:include ".$data["pagename"]."%"));
 126    if (is_array($rows)) {
 127      $rows[] = array("pagename"=>$data["pagename"]);
 128      foreach ($rows as $row) {
 129        $dir = SIMPLE_CACHE."/cms/".urlencode(strtolower($row["pagename"]));
 130        if (is_dir($dir)) {
 131          if (DEBUG) echo "delete ".$dir;
 132          dirs_delete_all($dir,0,false);
 133  } } } }
 134  
 135  static function deletecms($id, $data, $unused, $table) {
 136    db_update($table,array("activated"=>"0"),array("id=@id@"),array("id"=>$id));
 137    $dir = SIMPLE_CACHE."/cms/".urlencode($data["pagename"]);
 138    if (is_dir($dir)) dirs_delete_all($dir,0,true);
 139    return "";
 140  }
 141  
 142  // e.g. addgroupmember(0, array("username"=>$username), array($group))
 143  static function addgroupmember($id, $data, $params) {
 144    if (empty($params[0]) or empty($data["username"])) return "";
 145    $groupname = $params[0];
 146    $members = db_select_value("simple_sys_groups","members","groupname=@name@",array("name"=>$groupname));
 147    if (!empty($members)) $members = explode("|",trim($members,"|")); else $members = array();
 148    $members[] = $data["username"];
 149    $members = implode("|",array_unique($members));
 150    db_update("simple_sys_groups",array("members"=>"|".$members."|"),array("groupname=@name@"),array("name"=>$groupname));
 151    return "";
 152  }
 153  
 154  static function setgroupmembers($group, $members) {
 155    if ($members!="") $members = "|".trim($members,"|")."|";
 156    db_update("simple_sys_groups",array("members"=>$members),array("groupname=@group@"),array("group"=>$group));
 157    // TODO notify?
 158  }
 159  
 160  static function creategroup($name) {
 161    $row_id = db_select_value("simple_sys_groups","id","groupname=@name@",array("name"=>$name));
 162    $folder = folder_from_path("~sys_groups");
 163    
 164    if (empty($row_id) and !empty($folder)) {
 165      $id = sql_genID("simple_sys_groups")*100+$_SESSION["serverid"];
 166      $data = array("id"=>$id, "groupname"=>$name, "activated"=>1, "folder"=>$folder);
 167      $error_sql = db_insert("simple_sys_groups",$data);
 168      if ($error_sql=="") {
 169        db_update_treesize("simple_sys_groups",$folder);
 170        db_search_update("simple_sys_groups",$id,array(),array("groupname"=>"text"));
 171        sys_log_stat("new_records",1);
 172        sys_notification(sprintf("{t}Group created.{/t} (%s)", $name));
 173      } else return $error_sql;
 174    }
 175    return "";
 176  }
 177  
 178  static function editgroup($id, $data) {
 179    if ($data["members"]!="") $data["members"] = "|".trim($data["members"],"|")."|";
 180    if (sys_strbegins($data["groupname"],"project_")) {
 181      $project = substr($data["groupname"],8);
 182      db_update("simple_projects",array("participants"=>$data["members"]),array("projectname=@project@"),array("project"=>$project));
 183      sys_notification("{t}Update{/t} {t}Participants{/t}: {t}Project{/t} ".$project);
 184    }
 185    if (sys_strbegins($data["groupname"],"department_")) {
 186      $department = substr($data["groupname"],11);
 187      db_update("simple_departments",array("members"=>$data["members"]),array("departmentname=@department@"),array("department"=>$department));
 188      sys_notification("{t}Update{/t} {t}Members{/t}: {t}Department{/t} ".$department);
 189    }
 190    return "";
 191  }
 192  
 193  static function createeditproject($id, $data) {
 194    if ($data["finishsched"]!=0 and $data["startsched"]!=0) {
 195      db_update("simple_projects",array("duration"=>$data["finishsched"]-$data["startsched"]),array("id=@id@"),array("id"=>$id));
 196    }
 197    self::creategroup("project_".$data["projectname"]);
 198    self::setgroupmembers("project_".$data["projectname"], $data["participants"]);
 199    return "";
 200  }
 201  
 202  static function createeditdepartment($id, $data) {
 203    self::creategroup("department_".$data["departmentname"]);
 204    self::setgroupmembers("department_".$data["departmentname"], $data["members"]);
 205    return "";
 206  }
 207  
 208  static function deleteproject($id, $data) {
 209    $count = db_select_value("simple_projects","count(*) as count","projectname=@projectname@",array("projectname"=>$data["projectname"]));
 210    $row_id = folder_from_path("^projects_".$data["projectname"]);
 211  
 212    if (!empty($count) and !empty($row_id)) {
 213      folders::delete($row_id);
 214      sys_notification(sprintf("{t}Folder structure moved to trash.{/t} (%s)", $data["projectname"]));
 215    }
 216    self::deletegroup_by_name("project_".$data["projectname"]);
 217    return "";
 218  }
 219  
 220  static function deletedepartment($id, $data) {
 221    $count = db_select_value("simple_departments","count(*) as count","departmentname=@departmentname@",array("departmentname"=>$data["departmentname"]));
 222    $row_id = folder_from_path("^departments_".$data["departmentname"]);
 223  
 224    if (!empty($count) and !empty($row_id)) {
 225      folders::delete($row_id);
 226      sys_notification(sprintf("{t}Folder structure moved to trash.{/t} (%s)", $data["departmentname"]));
 227    }
 228    self::deletegroup_by_name("department_".$data["departmentname"]);
 229    return "";
 230  }
 231  
 232  static function deletechat($id, $data) {
 233    $count = db_select_value("simple_chat","count(*) as count","roomname=@roomname@",array("roomname"=>$data["roomname"]));
 234    if ($count==1) db_delete("simple_sys_chat2",array("room=@room@"),array("room"=>$data["roomname"]));
 235    return "";
 236  }
 237  
 238  static function sendmail_pop3($id, $data) {
 239    return self::sendmail($id, $data, null, "", true);
 240  }
 241  
 242  static function sendmail($id, $data, $unused, $table, $to_self=false) {
 243    if (isset($data["sendnow"]) and $data["sendnow"]==0) return "";
 244  
 245    $row = self::sendmail_getconn($_SESSION["username"],$data["efrom"]);
 246    if (USE_MAIL_FUNCTION or !empty($row["smtp"])) {
 247      if (!empty($row["smtp"])) sys_credentials($data["folder"], "smtp:".$row["smtp"]."/");
 248      if (!empty($row["email"])) $data["efrom"] = $row["email"];
 249      if (!empty($row["name"])) $data["name"] = $row["name"];
 250      $result = lib_smtp::insert("",$data,$data["folder"],$to_self,USE_MAIL_FUNCTION,true);
 251      if (is_array($result)) {
 252        if ($table!="" and !strpos($table, "_nodb_")) db_update($table,array("headers"=>implode("\n", $result)),array("id=@id@"),array("id"=>$id));
 253        $result = "";
 254      }
 255      if (empty($result) and sys_strbegins($data["subject"],SMTP_NOTIFICATION)) {
 256        sys_notification(sprintf("{t}Notificaiton sent to: %s{/t}", $data["eto"]));
 257      }
 258    } else {
 259      $result = sprintf("{t}Mail identities{/t}: {t}SMTP not configured for %s{/t}",$_SESSION["username"]);
 260    }
 261    return $result;
 262  }
 263  
 264  static function createemail($id, $data, $unused, $table) {
 265    if (empty($data["message_html"]) and !empty($data["message"])) {
 266      $message_html = nl2br(modify::htmlquote(trim($data["message"])));
 267      db_update($table,array("message_html"=>$message_html),array("id=@id@"),array("id"=>$id));
 268    }
 269    if (empty($data["message"]) and !empty($data["message_html"])) {
 270      $message = modify::htmlmessage($data["message_html"]);
 271      db_update($table,array("message"=>$message),array("id=@id@"),array("id"=>$id));
 272    }
 273    return "";
 274  }
 275  
 276  static function calcappointment($id, $data, $unused, $table) {
 277    if ($data["begin"] > $data["ending"]) {
 278      $tmp = $data["begin"];
 279      $data["begin"] = $data["ending"];
 280      $data["ending"] = $tmp;
 281    }
 282    if (isset($data["allday"]) and $data["allday"]=="1") {
 283      $begin_arr = sys_getdate($data["begin"]);
 284      $data["begin"] = mktime(0,0,0,$begin_arr["mon"],$begin_arr["mday"],$begin_arr["year"]);
 285      $end_arr = sys_getdate($data["ending"]);
 286      $data["ending"] = mktime(23,59,0,$end_arr["mon"],$end_arr["mday"],$end_arr["year"]);
 287    }
 288    $repeatbegin = 0;
 289    $repeatend = 0;
 290    if (!empty($data["recurrence"])) {
 291      switch ($data["recurrence"]) {
 292      case "weeks":
 293        $repeatbegin = sys_date("w",$data["begin"]);
 294        $repeatend = sys_date("w",$data["ending"]);
 295        break;
 296      case "months":
 297        $repeatbegin = sys_date("j",$data["begin"]);
 298        $repeatend = sys_date("j",$data["ending"]);
 299        break;
 300      case "years":
 301        $repeatbegin = sys_date("z",$data["begin"]);
 302        $repeatend = sys_date("z",$data["ending"]);
 303        if ($repeatbegin > 58) $repeatbegin--; // leap year
 304        if ($repeatend > 58) $repeatend++;
 305        break;
 306      }
 307    }
 308  
 309    $datas = array("begin"=>$data["begin"], "ending"=>$data["ending"], "duration"=>$data["ending"] - $data["begin"],
 310      "repeatbegin"=>$repeatbegin, "repeatend"=>$repeatend);
 311  
 312    $begin = strtotime("00:00:00", $data["begin"]);
 313    $days = min(ceil(($data["ending"] - $begin) / 86400), 31);
 314  
 315    $occurs = array();
 316    $occurs_weeks = array();
 317    self::_get_occurrence($begin, $days, $occurs, $occurs_weeks);
 318    $diff = $data["begin"] - $begin;
 319    $max_recurrence = strtotime("+3 years", NOW);
 320    
 321    $recurs = array();
 322    if (!empty($data["recurrence"])) {
 323      $recurs[] = $begin + $diff;
 324      $excludes = explode("|",$data["repeatexcludes"]);
 325      $counter = 0;
 326      while ($data["repeatcount"]!=1 and $counter < 150 and $begin < $max_recurrence) {
 327        $begin = strtotime("+".(int)($data["repeatinterval"])." ".$data["recurrence"], $begin);
 328  
 329        if ($data["repeatuntil"]!=0 and $begin > $data["repeatuntil"]) break;
 330        if (in_array($begin, $excludes)) continue;
 331  
 332        self::_get_occurrence($begin, $days, $occurs, $occurs_weeks);
 333        $recurs[] = $begin + $diff;
 334        if ($data["repeatcount"]!=0) $data["repeatcount"]--;
 335        $counter++;
 336      }
 337    }
 338    if (!empty($occurs)) {
 339      $datas["until"] = strtotime(preg_replace("!(\d{2})(\d{2})(\d{2})!", "\\1-\\2-\\3", $occurs[count($occurs)-1]));
 340    } else {
 341      $datas["until"] = $data["ending"];
 342    }
 343    $datas["occurs"] = self::_scalarize($occurs);
 344    $datas["occurs_weeks"] = self::_scalarize(array_unique($occurs_weeks));
 345    $datas["recurs"] = self::_scalarize($recurs);
 346    
 347    if ($id!="") {
 348      db_update($table, $datas, array("id=@id@"), array("id"=>$id));
 349      self::notify($id, array_merge($data, $datas), array(), $table);
 350    } else {
 351      return $datas;
 352    }
 353    return "";
 354  }
 355  
 356  private static function _scalarize($value) {
 357    if (empty($value)) return "";
 358    return "|".implode("|", $value)."|";
 359  }
 360  
 361  private static function _get_occurrence($begin, $days, &$occurs, &$occurs_weeks) {
 362    for ($i=0; $i<$days; $i++) {
 363      $occurs[] = date("ymd", $begin);
 364      $occurs_weeks[] = date("y\wW", $begin);
 365      $begin += 86400;
 366    }
 367  }
 368  
 369  static function runxml($id, $data, $params) {
 370    list($file, $parent_anchor) = $params;
 371    $home = folder_from_path("^".$parent_anchor);
 372    if (!empty($home) and file_exists(sys_custom($file))) {
 373      sys_notification(sprintf("{t}Processing %s ...{/t}", $file));
 374      $folder = folders::create_default_folders($file,$home,false,$data);
 375      sys_notification(sprintf("{t}Folder structure created.{/t} (%s)", modify::getpath($folder)." / "));
 376    }
 377    return "";
 378  }
 379  
 380  static function create_ldap_user($ds, $base_dn, $username, $uid) {
 381    if ($base_dn=="") {
 382      $result_id = @ldap_read($ds,"","(objectclass=*)",array("namingContexts"));
 383      $attrs = ldap_get_attributes($ds, ldap_first_entry($ds,$result_id));
 384      $base_dn = $attrs["namingContexts"][0];
 385    }
 386    $res = ldap_search($ds,$base_dn,$uid."=".$username);
 387    if (ldap_count_entries($ds,$res)==1) {
 388      $data = ldap_get_attributes($ds, ldap_first_entry($ds,$res));
 389      if (is_array($data) and count($data)!=0) self::_create_ldap_user($username,$data);
 390    }
 391  }
 392  
 393  static function http_post($host, $port, $path, $data) {
 394    $errorNumber = 0;
 395    $errorString = "";
 396    if (($fp = @fsockopen($host, $port, $errorNumber, $errorString))) {
 397      $req = array();
 398      $req[] = "POST ".$path." HTTP/1.0";
 399      $req[] = "Host: ".$host;
 400      $req[] = "Content-Type: application/x-www-form-urlencoded";
 401      $req[] = "Content-Length: ".strlen($data);
 402      $req[] = "";
 403      $req[] = $data;
 404      fwrite($fp, implode("\r\n", $req));
 405      $resp = "";
 406      while (!feof($fp)) $resp .= fread($fp,8192);
 407      fclose($fp);
 408      return $resp;
 409    } else {
 410      return "ERROR: ".$errorString." ".$errorNumber;
 411    }
 412  }
 413  
 414  static function sendmail_getconn($username, $efrom) {
 415    $concat = sql_concat("concat(firstname;' ';lastname)");
 416    if ($efrom!="") {
 417      $row = db_select_first("simple_sys_identities",array("smtp","email","name"),array("email=@email@","users like @username_sql@"),"",array("username_sql"=>"%|".$username."|%","email"=>$efrom));
 418      if (empty($row["smtp"]) and !USE_MAIL_FUNCTION) {
 419        $row["smtp"] = db_select_value("simple_sys_users","smtp","username=@username@",array("username"=>$username));
 420      }
 421    } else {
 422      $row = db_select_first("simple_sys_users",array("smtp","email","$concat as name"),"username=@username@","",array("username"=>$username));
 423      if (empty($row["smtp"]) and !USE_MAIL_FUNCTION) {
 424        $row = db_select_first("simple_sys_identities",array("smtp","email","name"),"users like @username_sql@","",array("username_sql"=>"%|".$username."|%"));
 425      }
 426    }
 427    return $row;
 428  }
 429  
 430  static function createedit_payroll($id, $data, $unused, $table) {
 431    $cdata = array();
 432    if ($data["status"]!="open") {
 433      if ($data["rwrite_users"]!="") $cdata["rwrite_users"] = "";
 434      if ($data["rwrite_groups"]!="" and $data["rwrite_groups"]!="admin_payroll") $cdata["rwrite_groups"] = "";
 435      if (count($cdata)>0) {
 436        db_update($table,$cdata,array("id=@id@"),array("id"=>$id));
 437        sys_notification("{t}Asset marked as read-only.{/t}");
 438      }
 439      if (self::_add_asset_permission_group($table,$id,array_merge($data,$cdata),"admin_payroll")) {
 440        sys_notification(sprintf("{t}Permissions added for: %s{/t}", "admin_payroll"));
 441      }
 442    }
 443    return "";
 444  }
 445  
 446  private static function _createlocation($name) {
 447    $row_id = db_select_value("simple_locations","id","locationname=@name@",array("name"=>$name));
 448    $folder = folder_from_path("^locations");
 449  
 450    if (empty($row_id) and !empty($folder)) {
 451      $id = sql_genID("simple_locations")*100+$_SESSION["serverid"];
 452      $data = array("id"=>$id, "locationname"=>$name, "folder"=>$folder);
 453      $error_sql = db_insert("simple_locations",$data);
 454      if ($error_sql=="") {
 455        db_update_treesize("simple_locations",$folder);
 456        db_search_update("simple_locations",$id,array(),array("locationname"=>"text"));
 457        sys_log_stat("new_records",1);
 458      } else return $error_sql;
 459    }
 460    return "";
 461  }
 462  
 463  private static function _create_ldap_user($username, $data) {
 464    $cdata = array();
 465  
 466    $mapping = array(
 467      "c"=>"country", "department"=>"department", "description"=>"jobdesc",
 468      "facsimiletelephonenumber"=>"fax", "fax"=>"fax", "givenname"=>"firstname", "ipphone"=>"skype",
 469      "l"=>"city", "mail"=>"email", "mobile"=>"mobile", "pager"=>"pager", "postalcode"=>"zipcode",
 470      "sn"=>"lastname", "st"=>"state", "street"=>"street", "streetaddress"=>"street",
 471      "telephonenumber"=>"phone", "wwwhomepage"=>"homepage", SETUP_AUTH_LDAP_ROOM=>"location"
 472    );
 473    foreach ($data as $key=>$val) {
 474      $key = strtolower($key);
 475      if (isset($mapping[$key]) and !empty($val[0])) $cdata[$mapping[$key]] = $val[0];
 476    }
 477    
 478    $username = strtolower($username);
 479    login::create_user($username,$cdata);
 480    if (!empty($cdata["location"])) self::_createlocation($cdata["location"]);
 481  
 482    if (isset($data[SETUP_AUTH_LDAP_MEMBEROF])) $groups = $data[SETUP_AUTH_LDAP_MEMBEROF]; else $groups = array();
 483    
 484    if (SETUP_AUTH_LDAP_GROUPS and is_array($groups) and count($groups)>1) {
 485      array_shift($groups);
 486      self::_create_ldap_groups($groups, $username);
 487    }
 488  }
 489  
 490  private static function _create_ldap_groups($groups, $username) {
 491    db_update("simple_sys_groups",array("members"=>"replace(members,'|".sql_quote($username)."|','|')"),array("members like @username@","createdby='auth_ldap'"),array("username"=>"%|".$username."|%"),array("quote"=>false));
 492    foreach ($groups as $group) {
 493      $group = ldap_dn2ufn($group);
 494      $group = substr($group,0,strpos($group,","));
 495      if (empty($group)) continue;
 496      
 497      // decode 2-byte unicode characters
 498      $group = preg_replace("/\\\\([A-F0-9]{2})/e",'chr(hexdec("\1"))',$group);
 499      self::creategroup($group);
 500      self::addgroupmember(0, array("username"=>$username), array($group));
 501    }
 502  }
 503  
 504  private static function _add_asset_permission_group($table, $id, $data, $group) {
 505    $cdata = array();
 506    if (!in_array($group,explode("|",$data["rread_groups"]))) {
 507      $cdata["rread_groups"] = $data["rread_groups"]."|".$group;
 508    }
 509    if (!in_array($group,explode("|",$data["rwrite_groups"]))) {
 510      $cdata["rwrite_groups"] = $data["rwrite_groups"]."|".$group;
 511    }
 512    if (count($cdata)==0) return false;
 513    foreach ($cdata as $key=>$val) $cdata[$key] = "|".trim($val,"|")."|";
 514    db_update($table,$cdata,array("id=@id@"),array("id"=>$id));
 515    return true;
 516  }
 517  
 518  }

title

Description

title

Description

title

Description

title

title

Body