Group-Office PHP Cross Reference Groupware Applications

Source: /functions.inc.php - 515 lines - 13167 bytes - Summary - Text - Print

Description: Copyright Intermesh

   1  <?php
   2  /**
   3   * Copyright Intermesh
   4   *
   5   * This file is part of Group-Office. You should have received a copy of the
   6   * Group-Office license along with Group-Office. See the file /LICENSE.TXT
   7   *
   8   * If you have questions write an e-mail to info@intermesh.nl
   9   *
  10   * @copyright Copyright Intermesh
  11   * @version $Id: functions.inc.php 16826 2014-02-12 16:38:07Z mschering $
  12   * @author Merijn Schering <mschering@intermesh.nl>
  13   */
  14  
  15  
  16  //if ( !function_exists( 'get_called_class' ) ) {
  17  //    function get_called_class ()
  18  //    {
  19  //        $t = debug_backtrace(); $t = $t[0];
  20  //        if ( isset( $t['object'] ) && $t['object'] instanceof $t['class'] )
  21  //            return get_class( $t['object'] );
  22  //        return false;
  23  //    }
  24  //} 
  25  
  26  
  27  function get_model_by_type_id($model_type_id){
  28      require_once ('GO.php');
  29      $db = new db();
  30      $sql = "SELECT model_name FROM go_model_types WHERE id=$model_type_id";
  31          $db->query($sql);
  32          $r = $db->next_record();
  33          if(empty($r['model_name']))
  34              return false;
  35              
  36          return GO::getModel($r['model_name']);
  37  }
  38  
  39  
  40  function ini_return_bytes($val) {
  41      $val = trim($val);
  42      $last = strtolower($val[strlen($val)-1]);
  43      switch($last) {
  44          // The 'G' modifier is available since PHP 5.1.0
  45          case 'g':
  46              $val *= 1024;
  47          case 'm':
  48              $val *= 1024;
  49          case 'k':
  50              $val *= 1024;
  51      }
  52  
  53      return $val;
  54  }
  55  
  56  
  57  function load_standard_info_panel_items(&$response, $link_type) {
  58      global $GO_CONFIG, $GO_MODULES, $GO_SECURITY;
  59  
  60      $hidden_sections = json_decode($_POST['hidden_sections'], true);
  61      
  62      require_once($GLOBALS['GO_CONFIG']->class_path . '/base/search.class.inc.php');
  63      $search = new search();
  64  
  65      if (/*!in_array('links', $hidden_sections) && */!isset($response['data']['links'])) {
  66          $links_json = $search->get_latest_links_json($GLOBALS['GO_SECURITY']->user_id, $response['data']['id'], $link_type);
  67          $response['data']['links'] = $links_json['results'];
  68      }
  69  
  70      if (/*isset($GLOBALS['GO_MODULES']->modules['tasks']) && !in_array('tasks', $hidden_sections) &&*/ !isset($response['data']['tasks'])) {
  71          require_once($GLOBALS['GO_MODULES']->modules['tasks']['class_path'] . 'tasks.class.inc.php');
  72          $tasks = new tasks();
  73  
  74          $response['data']['tasks'] = $tasks->get_linked_tasks_json($response['data']['id'], $link_type);
  75      }
  76  
  77      if (isset($GLOBALS['GO_MODULES']->modules['calendar'])/* && !in_array('events', $hidden_sections)*/) {
  78          require_once($GLOBALS['GO_MODULES']->modules['calendar']['class_path'] . 'calendar.class.inc.php');
  79          $cal = new calendar();
  80  
  81          $response['data']['events'] = $cal->get_linked_events_json($response['data']['id'], $link_type);
  82      }
  83  
  84      if (/*!in_array('files', $hidden_sections) && */!isset($response['data']['files'])) {
  85          if (isset($GLOBALS['GO_MODULES']->modules['files'])) {
  86              require_once($GLOBALS['GO_MODULES']->modules['files']['class_path'] . 'files.class.inc.php');
  87              $files = new files();
  88  
  89              $response['data']['files'] = $files->get_content_json($response['data']['files_folder_id']);
  90          } else {
  91              $response['data']['files'] = array();
  92          }
  93      }
  94  
  95  
  96      if (/*!in_array('comments', $hidden_sections) && */isset($GLOBALS['GO_MODULES']->modules['comments']) && !isset($response['data']['comments'])) {
  97          require_once ($GLOBALS['GO_MODULES']->modules['comments']['class_path'] . 'comments.class.inc.php');
  98          $comments = new comments();
  99  
 100          $response['data']['comments'] = $comments->get_comments_json($response['data']['id'], $link_type);
 101      }
 102  
 103      if($GLOBALS['GO_MODULES']->has_module('customfields') && !isset($response['data']['customfields']))
 104      {
 105          require_once($GLOBALS['GO_MODULES']->modules['customfields']['class_path'].'customfields.class.inc.php');
 106          $cf = new customfields();
 107          $response['data']['customfields']=$cf->get_all_fields_with_values($GLOBALS['GO_SECURITY']->user_id, $link_type, $response['data']['id']);
 108      }
 109  
 110  }
 111  
 112  /**
 113   * Function array_insert().
 114   *
 115   * Returns the new number of the elements in the array.
 116   *
 117   * @param array $array Array (by reference)
 118   * @param mixed $value New element
 119   * @param int $offset Position
 120   * @return int
 121   */
 122  function array_insert(&$array, $value, $offset)
 123  {
 124      if (is_array($array)) {
 125          $array  = array_values($array);
 126          $offset = intval($offset);
 127          if ($offset < 0 || $offset >= count($array)) {
 128              array_push($array, $value);
 129          } elseif ($offset == 0) {
 130              array_unshift($array, $value);
 131          } else {
 132              $temp  = array_slice($array, 0, $offset);
 133              array_push($temp, $value);
 134              $array = array_slice($array, $offset);
 135              $array = array_merge($temp, $array);
 136          }
 137      } else {
 138          $array = array($value);
 139      }
 140      return count($array);
 141  }
 142  
 143  function set_multiselectgrid_selections($key, $ids, $user_id){
 144      global $GO_CONFIG;
 145      $value = is_array($ids) ? implode(',', $ids) : $ids;
 146  
 147      $GLOBALS['GO_CONFIG']->save_setting('msg_'.$key,$value, $user_id);
 148  }
 149  
 150  /*
 151   * Get's and saves the selected id's from a MultiSelectGrid
 152   */
 153  
 154  function get_multiselectgrid_selections($key){
 155      global $GO_CONFIG, $GO_SECURITY;
 156  
 157      
 158      if(isset($_POST[$key]))
 159      {
 160          $ids = json_decode($_POST[$key], true);
 161          $GLOBALS['GO_CONFIG']->save_setting('msg_'.$key,implode(',', $ids), $GLOBALS['GO_SECURITY']->user_id);
 162      }else
 163      {
 164          $ids = $GLOBALS['GO_CONFIG']->get_setting('msg_'.$key, $GLOBALS['GO_SECURITY']->user_id);
 165          $ids = $ids ? explode(',',$ids) : array();
 166      }
 167      return $ids;
 168  }
 169  
 170  function in_multiselectgrid_selection($target,$key) {
 171      global $GO_CONFIG, $GO_SECURITY;
 172      $array = get_multiselectgrid_selections($key);
 173      return in_array($target,$array);
 174  }
 175  
 176  /**
 177   *
 178   * @global <type> $GO_CONFIG
 179   * @param <type> $module The name of the module
 180   * @param <type> $function the name of the function GO.<module>.<function> must be created
 181   * @param <type> $params Array of parameters. The javascript function will be called like foo(arr[0],arr[1],arr[2], etc){}
 182   * @param <type> $loadevent Call this function before Group-Office renders with ready or after with render
 183   * @return <type> An URL that can call a Group-Office function directly
 184   */
 185  
 186  
 187  function create_direct_url($module, $function, $params, $loadevent='render')
 188  {
 189      global $GO_CONFIG;
 190  
 191      return $GLOBALS['GO_CONFIG']->orig_full_url.'dialog.php?e='.$loadevent.'&m='.$module.'&f='.$function.'&p='.urlencode(base64_encode(json_encode($params)));
 192  }
 193  
 194  
 195  /**
 196   * This file holds global functions for use inside Group-Office
 197   *
 198   * @package go.global
 199   * @copyright Copyright Intermesh
 200   * @version $Id: functions.inc.php 16826 2014-02-12 16:38:07Z mschering $
 201   * @author Merijn Schering <mschering@intermesh.nl>
 202   * @since    Group-Office 1.0
 203   */
 204  
 205  
 206   function google_maps_link($address, $address_no, $city, $country){
 207       $l='';
 208  
 209      if(!empty($address) && !empty($city))
 210      {
 211          $l .= $address;
 212          if(!empty($address_no)){
 213              $l .= ' '.$address_no.', '.$city;
 214          }else
 215          {
 216              $l .= ', '.$city;
 217          }
 218  
 219          if(!empty($country)){
 220              $l .= ', '.$country;
 221          }
 222  
 223          return 'http://maps.google.com/maps?q='.urlencode($l);
 224      }else
 225      {
 226          return false;
 227      }
 228   }
 229  
 230  
 231  /**
 232   * Attempts to autoload class files
 233   *
 234   * @param string $class_name
 235   */
 236  
 237  function go_autoload($class_name) {
 238      global $GO_CONFIG;
 239  
 240      /*if(!file_exists($GLOBALS['GO_CONFIG']->class_path. $class_name.'.class.inc.php'))
 241          {
 242          debug_print_backtrace();
 243          }*/
 244      if(isset($GO_CONFIG)){
 245          $cls = $GLOBALS['GO_CONFIG']->class_path. $class_name.'.class.inc.php';
 246          if(file_exists($cls))
 247              require_once $cls;
 248      }
 249  }
 250  spl_autoload_register("go_autoload");
 251  
 252  
 253  function is_windows(){
 254      return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
 255  }
 256  
 257  /**
 258   * Get the current server time in microseconds
 259   *
 260   * @access public
 261   * @return int
 262   */
 263  function getmicrotime() {
 264      list ($usec, $sec) = explode(" ", microtime());
 265      return ((float) $usec + (float) $sec);
 266  }
 267  
 268  /**
 269   * Get's the last file or directory name of a filesystem path and works
 270   * with UTF-8 too unlike the basename function in PHP.
 271   *
 272   * @param string $path
 273   * @return string basename
 274   */
 275  
 276  function utf8_basename($path)
 277  {
 278      if(!function_exists('mb_substr'))
 279      {
 280          return basename($path);
 281      }
 282      //$path = trim($path);
 283      if(substr($path,-1,1)=='/')
 284      {
 285          $path = substr($path,0,-1);
 286      }
 287      if(empty($path))
 288      {
 289          return '';
 290      }
 291      $pos = mb_strrpos($path, '/');
 292      if($pos===false)
 293      {
 294          return $path;
 295      }else
 296      {
 297          return mb_substr($path, $pos+1);
 298      }
 299  }
 300  
 301  /**
 302   * Add a log entry to syslog if enabled in config.php
 303   *
 304   * @param    int $level The log level. See sys_log() of the PHP docs
 305   * @param    string $message The log message
 306   * @access public
 307   * @return void
 308   */
 309  function go_log($level, $message) {
 310      global $GO_CONFIG;
 311      if ($GLOBALS['GO_CONFIG']->log) {
 312          $messages = str_split($message, 500);
 313          for ($i = 0; $i < count($messages); $i ++) {
 314              syslog($level, $messages[$i]);
 315          }
 316      }
 317  }
 318  
 319  function go_infolog($message){
 320      global $GO_CONFIG;
 321      if ($GLOBALS['GO_CONFIG']->log) {
 322          
 323          if(empty($_SESSION['GO_SESSION']['logdircheck'])){
 324              File::mkdir(dirname($GLOBALS['GO_CONFIG']->info_log));
 325              $_SESSION['GO_SESSION']['logdircheck']=true;
 326          }
 327          
 328          $msg = '['.date('Y-m-d G:i:s').']';
 329          
 330          if(!empty($_SESSION['GO_SESSION']['username'])){
 331              $msg .= '['.$_SESSION['GO_SESSION']['username'].'] ';
 332          }
 333          
 334          $msg.= $message;
 335          
 336          @file_put_contents($GLOBALS['GO_CONFIG']->info_log, $msg."\n", FILE_APPEND);
 337      }
 338  }
 339  
 340  /**
 341   * Set's the debug log location
 342   *
 343   * @param string $file
 344   */
 345  
 346  function set_debug_log($file)
 347  {
 348      $_SESSION['GO_SESSION']['debug_log']=$file;
 349  }
 350  
 351  /**
 352   * Write's to a debug log.
 353   *
 354   * @param string $text log entry
 355   */
 356  
 357  function go_debug($text, $config=false)
 358  {
 359  
 360      if(!$config)
 361          $config=$GLOBALS['GO_CONFIG'];
 362  
 363      if($config->debug || $config->debug_log)
 364      {
 365          if(!is_string($text))
 366          {
 367              $text = var_export($text, true);
 368          }
 369  
 370          if($text=='')
 371              $text = '(empty string)';
 372  
 373  //        if(PHP_SAPI=='cli')
 374  //        {
 375  //            echo 'DEBUG: '.$text."\n\n";
 376  //            return;
 377  //        }
 378  
 379          if(!isset($_SESSION['GO_SESSION']['debug_log']))
 380          $_SESSION['GO_SESSION']['debug_log']=$config->file_storage_path.'debug.log';
 381  
 382          file_put_contents($_SESSION['GO_SESSION']['debug_log'], $text."\n", FILE_APPEND);
 383      }
 384  }
 385  
 386  
 387  /**
 388   * Returns an array with browser information
 389   *
 390   * @access public
 391   * @return array Array contains keys name, version and subversion
 392   */
 393  function detect_browser() {
 394      if (preg_match("'msie ([0-9].[0-9]{1,2})'i", $_SERVER['HTTP_USER_AGENT'], $log_version)) {
 395          $browser['version'] = $log_version[1];
 396          $browser['name'] = 'MSIE';
 397      }
 398      elseif (preg_match("'opera/([0-9].[0-9]{1,2})'i", $_SERVER['HTTP_USER_AGENT'], $log_version)) {
 399          $browser['version'] = $log_version[1];
 400          $browser['name'] = 'OPERA';
 401      }
 402      elseif (preg_match("'mozilla/([0-9].[0-9]{1,2}).*gecko/([0-9]+)'i", $_SERVER['HTTP_USER_AGENT'], $log_version)) {
 403          $browser['version'] = $log_version[1];
 404          $browser['name'] = 'MOZILLA';
 405          $browser['subversion'] = $log_version[2];
 406      }
 407      elseif (preg_match("'netscape/([0-9].[0-9]{1,2})'i", $_SERVER['HTTP_USER_AGENT'], $log_version)) {
 408          $browser['version'] = $log_version[1];
 409          $browser['name'] = 'NETSCAPE';
 410      }
 411      elseif (preg_match("'safari/([0-9]+.[0-9]+)'i", $_SERVER['HTTP_USER_AGENT'], $log_version)) {
 412          $browser['version'] = $log_version[1];
 413          $browser['name'] = 'SAFARI';
 414      } else {
 415          $browser['version'] = 0;
 416          $browser['name'] = 'OTHER';
 417      }
 418      return $browser;
 419  }
 420  
 421  function get_thumb_dir(){
 422      global $GO_CONFIG;
 423  
 424      require_once($GLOBALS['GO_CONFIG']->class_path.'base/theme.class.inc.php');
 425      $GO_THEME = new GO_THEME();
 426  
 427  
 428      if(is_dir($GLOBALS['GO_THEME']->theme_path.'images/128x128/filetypes/')){
 429          $dir = $GLOBALS['GO_THEME']->image_path.'128x128/filetypes/';
 430          $url = $GLOBALS['GO_THEME']->image_url.'128x128/filetypes/';
 431      }else{
 432          $dir = $GLOBALS['GO_CONFIG']->theme_path.'Default/images/128x128/filetypes/';
 433          $url = $GLOBALS['GO_CONFIG']->theme_url.'Default/images/128x128/filetypes/';
 434      }
 435  
 436      return array('url'=>$url,'dir'=>$dir);
 437  }
 438  
 439  function get_thumb_url($path, $w=100,$h=100,$zc=1) {
 440          global $GO_CONFIG;
 441  
 442          require_once($GLOBALS['GO_CONFIG']->class_path.'base/theme.class.inc.php');
 443          $GO_THEME = new GO_THEME();
 444  
 445  
 446          $extension = File::get_extension($path);
 447  
 448          $arr = get_thumb_dir();
 449  
 450          $url = $arr['url'];
 451          $dir = $arr['dir'];
 452          
 453  
 454          switch($extension) {
 455              case 'ico':
 456              case 'jpg':
 457              case 'jpeg':
 458              case 'png':
 459              case 'gif':
 460              case 'xmind':
 461                  return $GLOBALS['GO_CONFIG']->control_url.'thumb.php?src='.urlencode($path).'&w='.$w.'&h='.$h.'&zc='.$zc.'&filemtime='.@filemtime($GLOBALS['GO_CONFIG']->file_storage_path.$path).'&filectime='.@filectime($GLOBALS['GO_CONFIG']->file_storage_path.$path);
 462                  break;
 463  
 464              case 'pdf':
 465                  return $url.'pdf.png';
 466                  break;
 467  
 468              case 'tar':
 469              case 'tgz':
 470              case 'gz':
 471              case 'bz2':
 472              case 'zip':
 473                  return $url.'zip.png';
 474                  break;
 475              case 'odt':
 476              case 'docx':
 477              case 'doc':
 478                  return $url.'doc.png';
 479                  break;
 480  
 481              case 'odc':
 482              case 'ods':
 483              case 'xls':
 484              case 'xlsx':
 485                  return $url.'spreadsheet.png';
 486                  break;
 487  
 488              case 'odp':
 489              case 'pps':
 490              case 'pptx':
 491              case 'ppt':
 492                  return $url.'pps.png';
 493                  break;
 494              case 'eml':
 495                  return $url.'message.png';
 496                  break;
 497  
 498              case 'htm':
 499                  return $url.'doc.png';
 500                  break;
 501  
 502              case 'log':
 503                  return $url.'txt.png';
 504                  break;
 505  
 506              default:
 507                  if(file_exists($dir.$extension.'.png')) {
 508                      return $url.$extension.'.png';
 509                  }else {
 510                      return $url.'unknown.png';
 511                  }
 512                  break;
 513  
 514          }
 515  }

title

Description

title

Description

title

Description

title

title

Body