[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/com_vtiger_workflow/ -> VTWorkflowUtils.php (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  
  11  //A collection of util functions for the workflow module
  12  
  13  class VTWorkflowUtils {
  14      static $userStack;
  15      static $loggedInUser;
  16  
  17  	function __construct() {
  18          global $current_user;
  19          if(empty(self::$userStack)) {
  20              self::$userStack = array();
  21          }
  22      }
  23  
  24      /**
  25       * Check whether the given identifier is valid.
  26       */
  27  	function validIdentifier($identifier) {
  28          if (is_string($identifier)) {
  29              return preg_match("/^[a-zA-Z][a-zA-Z_0-9]+$/", $identifier);
  30          } else {
  31              return false;
  32          }
  33      }
  34  
  35      /**
  36       * Push the admin user on to the user stack
  37       * and make it the $current_user
  38       *
  39       */
  40  	function adminUser() {
  41          $user = Users::getActiveAdminUser();
  42          global $current_user;
  43          if (empty(self::$userStack) || count(self::$userStack) == 0) {
  44              self::$loggedInUser = $current_user;
  45          }
  46          array_push(self::$userStack, $current_user);
  47          $current_user = $user;
  48          return $user;
  49      }
  50  
  51      /**
  52       * Push the logged in user on the user stack
  53       * and make it the $current_user
  54       */
  55  	function loggedInUser() {
  56          $user = self::$loggedInUser;
  57          global $current_user;
  58          array_push(self::$userStack, $current_user);
  59          $current_user = $user;
  60          return $user;
  61      }
  62  
  63      /**
  64       * Revert to the previous use on the user stack
  65       */
  66  	function revertUser() {
  67          global $current_user;
  68          if (count(self::$userStack) != 0) {
  69              $current_user = array_pop(self::$userStack);
  70          } else {
  71              $current_user = null;
  72          }
  73          return $current_user;
  74      }
  75  
  76      /**
  77       * Get the current user
  78       */
  79  	function currentUser() {
  80          return $current_user;
  81      }
  82  
  83      /**
  84       * The the webservice entity type of an EntityData object
  85       */
  86  	function toWSModuleName($entityData) {
  87          $moduleName = $entityData->getModuleName();
  88          if ($moduleName == 'Activity') {
  89              $arr = array('Task' => 'Calendar', 'Emails' => 'Emails');
  90              $moduleName = $arr[getActivityType($entityData->getId())];
  91              if ($moduleName == null) {
  92                  $moduleName = 'Events';
  93              }
  94          }
  95          return $moduleName;
  96      }
  97  
  98      /**
  99       * Insert redirection script
 100       */
 101  	function redirectTo($to, $message) {
 102  ?>
 103          <script type="text/javascript" charset="utf-8">
 104              window.location="<?php echo $to ?>";
 105          </script>
 106          <a href="<?php echo $to ?>"><?php echo $message ?></a>
 107  <?php
 108      }
 109  
 110      /**
 111       * Check if the current user is admin
 112       */
 113  	function checkAdminAccess() {
 114          global $current_user;
 115          return strtolower($current_user->is_admin) === 'on';
 116      }
 117  
 118      /* function to check if the module has workflow
 119       * @params :: $modulename - name of the module
 120       */
 121  
 122  	function checkModuleWorkflow($modulename) {
 123          global $adb;
 124          $tabid = getTabid($modulename);
 125          $modules_not_supported = array('Calendar', 'Emails', 'Faq', 'Events' , 'Users');
 126          $query = "SELECT name FROM vtiger_tab WHERE name not in (" . generateQuestionMarks($modules_not_supported) . ") AND isentitytype=1 AND presence = 0 AND tabid = ?";
 127          $result = $adb->pquery($query, array($modules_not_supported, $tabid));
 128          $rows = $adb->num_rows($result);
 129          if ($rows > 0) {
 130              return true;
 131          } else {
 132              return false;
 133          }
 134      }
 135  
 136  	function vtGetModules($adb) {
 137          $modules_not_supported = array('Emails', 'PBXManager');
 138          $sql = "select distinct vtiger_field.tabid, name
 139              from vtiger_field
 140              inner join vtiger_tab
 141                  on vtiger_field.tabid=vtiger_tab.tabid
 142              where vtiger_tab.name not in(" . generateQuestionMarks($modules_not_supported) . ") and vtiger_tab.isentitytype=1 and vtiger_tab.presence in (0,2) ";
 143          $it = new SqlResultIterator($adb, $adb->pquery($sql, array($modules_not_supported)));
 144          $modules = array();
 145          foreach ($it as $row) {
 146              $modules[] = $row->name;
 147          }
 148          return $modules;
 149      }
 150  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1