[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Users/models/ -> Record.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  class Users_Record_Model extends Vtiger_Record_Model {
  12  
  13      /**
  14       * Gets the value of the key . First it will check whether specified key is a property if not it
  15       *  will get from normal data attribure from base class
  16       * @param <string> $key - property or key name
  17       * @return <object>
  18       */
  19  	public function get($key) {
  20          if(property_exists($this, $key)) {
  21              return $this->$key;
  22          }
  23          return parent::get($key);
  24      }
  25      
  26      /**
  27       * Sets the value of the key . First it will check whether specified key is a property if not it
  28       * will set from normal set from base class
  29       * @param <string> $key - property or key name
  30       * @param <string> $value
  31       */
  32      public function set($key, $value) {
  33          if(property_exists($this, $key)) {
  34              $this->$key = $value;
  35          }
  36          parent::set($key, $value);
  37          return $this;
  38      }
  39  
  40      /**
  41       * Function to get the Detail View url for the record
  42       * @return <String> - Record Detail View Url
  43       */
  44  	public function getDetailViewUrl() {
  45          $module = $this->getModule();
  46          return 'index.php?module='.$this->getModuleName().'&parent=Settings&view='.$module->getDetailViewName().'&record='.$this->getId();
  47      }
  48      
  49      /**
  50       * Function to get the Detail View url for the Preferences page
  51       * @return <String> - Record Detail View Url
  52       */
  53  	public function getPreferenceDetailViewUrl() {
  54          $module = $this->getModule();
  55          return 'index.php?module='.$this->getModuleName().'&view=PreferenceDetail&record='.$this->getId();
  56      }
  57      
  58      /**
  59       * Function to get the url for the Profile page
  60       * @return <String> - Profile Url
  61       */
  62  	public function getProfileUrl() {
  63          $module = $this->getModule();
  64          return 'index.php?module=Users&view=ChangePassword&mode=Profile';
  65      }
  66      
  67      /**
  68       * Function to get the Edit View url for the record
  69       * @return <String> - Record Edit View Url
  70       */
  71  	public function getEditViewUrl() {
  72          $module = $this->getModule();
  73          return 'index.php?module='.$this->getModuleName().'&parent=Settings&view='.$module->getEditViewName().'&record='.$this->getId();
  74      }
  75  
  76      /**
  77       * Function to get the Edit View url for the Preferences page
  78       * @return <String> - Record Detail View Url
  79       */
  80  	public function getPreferenceEditViewUrl() {
  81          $module = $this->getModule();
  82          return 'index.php?module='.$this->getModuleName().'&view=PreferenceEdit&record='.$this->getId();
  83      }
  84  
  85      /**
  86       * Function to get the Delete Action url for the record
  87       * @return <String> - Record Delete Action Url
  88       */
  89  	public function getDeleteUrl() {
  90          $module = $this->getModule();
  91          return 'index.php?module='.$this->getModuleName().'&parent=Settings&view='.$module->getDeleteActionName().'User&record='.$this->getId();
  92      }
  93  
  94      /**
  95       * Function to check whether the user is an Admin user
  96       * @return <Boolean> true/false
  97       */
  98  	public function isAdminUser() {
  99          $adminStatus = $this->get('is_admin');
 100          if ($adminStatus == 'on') {
 101              return true;
 102          }
 103          return false;
 104      }
 105  
 106      /**
 107       * Function to get the module name
 108       * @return <String> Module Name
 109       */
 110  	public function getModuleName() {
 111          $module = $this->getModule();
 112          if($module) {
 113              return parent::getModuleName();
 114          }
 115          //get from the class propety module_name
 116          return $this->get('module_name');
 117      }
 118  
 119      /**
 120       * Function to save the current Record Model
 121       */
 122  	public function save() {
 123          parent::save();
 124  
 125          $this->saveTagCloud();
 126      }
 127  
 128  
 129      /**
 130       * Function to get all the Home Page components list
 131       * @return <Array> List of the Home Page components
 132       */
 133  	public function getHomePageComponents() {
 134          $entity = $this->getEntity();
 135          $homePageComponents = $entity->getHomeStuffOrder($this->getId());
 136          return $homePageComponents;
 137      }
 138  
 139      /**
 140       * Static Function to get the instance of the User Record model for the current user
 141       * @return Users_Record_Model instance
 142       */
 143      protected static $currentUserModels = array();
 144  	public static function getCurrentUserModel() {
 145          //TODO : Remove the global dependency
 146          $currentUser = vglobal('current_user');
 147          if(!empty($currentUser)) {
 148              
 149              // Optimization to avoid object creation every-time
 150              // Caching is per-id as current_user can get swapped at runtime (ex. workflow)
 151              $currentUserModel = NULL;
 152              if (isset(self::$currentUserModels[$currentUser->id])) {
 153                  $currentUserModel = self::$currentUserModels[$currentUser->id];
 154                  if ($currentUser->column_fields['modifiedtime'] != $currentUserModel->get('modifiedtime')) {
 155                      $currentUserModel = NULL;
 156          }
 157              }
 158              if (!$currentUserModel) {
 159                  $currentUserModel = self::getInstanceFromUserObject($currentUser);
 160                  self::$currentUserModels[$currentUser->id] = $currentUserModel;
 161              }
 162              return $currentUserModel;
 163          }
 164          return new self();
 165      }
 166  
 167      /**
 168       * Static Function to get the instance of the User Record model from the given Users object
 169       * @return Users_Record_Model instance
 170       */
 171  	public static function getInstanceFromUserObject($userObject) {
 172          $objectProperties = get_object_vars($userObject);
 173          $userModel = new self();
 174          foreach($objectProperties as $properName=>$propertyValue){
 175              $userModel->$properName = $propertyValue;
 176          }
 177          return $userModel->setData($userObject->column_fields)->setModule('Users')->setEntity($userObject);
 178      }
 179  
 180      /**
 181       * Static Function to get the instance of all the User Record models
 182       * @return <Array> - List of Users_Record_Model instances
 183       */
 184  	public static function getAll($onlyActive=true) {
 185          $db = PearDatabase::getInstance();
 186  
 187          $sql = 'SELECT id FROM vtiger_users';
 188          $params = array();
 189          if($onlyActive) {
 190              $sql .= ' WHERE status = ?';
 191              $params[] = 'Active';
 192          }
 193          $result = $db->pquery($sql, $params);
 194  
 195          $noOfUsers = $db->num_rows($result);
 196          $users = array();
 197          if($noOfUsers > 0) {
 198              $focus = new Users();
 199              for($i=0; $i<$noOfUsers; ++$i) {
 200                  $userId = $db->query_result($result, $i, 'id');
 201                  $focus->id = $userId;
 202                  $focus->retrieve_entity_info($userId, 'Users');
 203  
 204                  $userModel = self::getInstanceFromUserObject($focus);
 205                  $users[$userModel->getId()] = $userModel;
 206              }
 207          }
 208          return $users;
 209      }
 210  
 211      /**
 212       * Function returns the Subordinate users
 213       * @return <Array>
 214       */
 215  	function getSubordinateUsers() {
 216          $privilegesModel = $this->get('privileges');
 217  
 218          if(empty($privilegesModel)) {
 219              $privilegesModel = Users_Privileges_Model::getInstanceById($this->getId());
 220              $this->set('privileges', $privilegesModel);
 221          }
 222  
 223          $subordinateUsers = array();
 224          $subordinateRoleUsers = $privilegesModel->get('subordinate_roles_users');
 225          if($subordinateRoleUsers) {
 226              foreach($subordinateRoleUsers as $role=>$users) {
 227                  foreach($users as $user) {
 228                      $subordinateUsers[$user] = $privilegesModel->get('first_name').' '.$privilegesModel->get('last_name');
 229                  }
 230              }
 231          }
 232          return $subordinateUsers;
 233      }
 234  
 235      /**
 236       * Function returns the Users Parent Role
 237       * @return <String>
 238       */
 239  	function getParentRoleSequence() {
 240          $privilegesModel = $this->get('privileges');
 241  
 242          if(empty($privilegesModel)) {
 243              $privilegesModel = Users_Privileges_Model::getInstanceById($this->getId());
 244              $this->set('privileges', $privilegesModel);
 245          }
 246  
 247          return $privilegesModel->get('parent_role_seq');
 248      }
 249  
 250      /**
 251       * Function returns the Users Current Role
 252       * @return <String>
 253       */
 254  	function getRole() {
 255          $privilegesModel = $this->get('privileges');
 256  
 257          if(empty($privilegesModel)) {
 258              $privilegesModel = Users_Privileges_Model::getInstanceById($this->getId());
 259              $this->set('privileges', $privilegesModel);
 260          }
 261  
 262          return $privilegesModel->get('roleid');
 263      }
 264  
 265      /**
 266       * Function returns List of Accessible Users for a Module
 267       * @param <String> $module
 268       * @return <Array of Users_Record_Model>
 269       */
 270  	public function getAccessibleUsersForModule($module) {
 271          $currentUser = Users_Record_Model::getCurrentUserModel();
 272          $curentUserPrivileges = Users_Privileges_Model::getCurrentUserPrivilegesModel();
 273  
 274          if($currentUser->isAdminUser() || $curentUserPrivileges->hasGlobalWritePermission()) {
 275              $users = $this->getAccessibleUsers("",$module);
 276          } else {
 277              $sharingAccessModel = Settings_SharingAccess_Module_Model::getInstance($module);
 278              if($sharingAccessModel->isPrivate()) {
 279                  $users = $this->getAccessibleUsers('private',$module);
 280              } else {
 281                  $users = $this->getAccessibleUsers("",$module);
 282              }
 283          }
 284          return $users;
 285      }
 286  
 287      /**
 288       * Function returns List of Accessible Users for a Module
 289       * @param <String> $module
 290       * @return <Array of Users_Record_Model>
 291       */
 292  	public function getAccessibleGroupForModule($module) {
 293          $currentUser = Users_Record_Model::getCurrentUserModel();
 294          $curentUserPrivileges = Users_Privileges_Model::getCurrentUserPrivilegesModel();
 295  
 296          if($currentUser->isAdminUser() || $curentUserPrivileges->hasGlobalWritePermission()) {
 297              $groups = $this->getAccessibleGroups("",$module);
 298          } else {
 299              $sharingAccessModel = Settings_SharingAccess_Module_Model::getInstance($module);
 300              if($sharingAccessModel->isPrivate()) {
 301                  $groups = $this->getAccessibleGroups('private',$module);
 302              } else {
 303                  $groups = $this->getAccessibleGroups("",$module);
 304              }
 305          }
 306          return $groups;
 307      }
 308  
 309      /**
 310       * Function to get Images Data
 311       * @return <Array> list of Image names and paths
 312       */
 313  	public function getImageDetails() {
 314          $currentUserModel = Users_Record_Model::getCurrentUserModel();
 315          $db = PearDatabase::getInstance();
 316  
 317          $imageDetails = array();
 318          $recordId = $this->getId();
 319  
 320          if ($recordId) {
 321              $query = "SELECT vtiger_attachments.* FROM vtiger_attachments
 322              LEFT JOIN vtiger_salesmanattachmentsrel ON vtiger_salesmanattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
 323              WHERE vtiger_salesmanattachmentsrel.smid=?";
 324  
 325              $result = $db->pquery($query, array($recordId));
 326  
 327              $imageId = $db->query_result($result, 0, 'attachmentsid');
 328              $imagePath = $db->query_result($result, 0, 'path');
 329              $imageName = $db->query_result($result, 0, 'name');
 330  
 331              //decode_html - added to handle UTF-8 characters in file names
 332              $imageOriginalName = decode_html($imageName);
 333  
 334              $imageDetails[] = array(
 335                      'id' => $imageId,
 336                      'orgname' => $imageOriginalName,
 337                      'path' => $imagePath.$imageId,
 338                      'name' => $imageName
 339              );
 340          }
 341          return $imageDetails;
 342      }
 343  
 344  
 345      /**
 346       * Function to get all the accessible users
 347       * @return <Array>
 348       */
 349  	public function getAccessibleUsers($private="",$module = false) {
 350          $currentUserRoleModel = Settings_Roles_Record_Model::getInstanceById($this->getRole());
 351          $accessibleUser = Vtiger_Cache::get('vtiger-'.$this->getRole().'-'.$currentUserRoleModel->get('allowassignedrecordsto'), 'accessibleusers');
 352          if(empty($accessibleUser)) {
 353              if($currentUserRoleModel->get('allowassignedrecordsto') === '1' || $private == 'Public') {
 354                  $accessibleUser = get_user_array(false, "ACTIVE", "", $private,$module);
 355              } else if($currentUserRoleModel->get('allowassignedrecordsto') === '2'){
 356                  $accessibleUser = $this->getSameLevelUsersWithSubordinates();
 357              } else if($currentUserRoleModel->get('allowassignedrecordsto') === '3') {
 358                  $accessibleUser = $this->getRoleBasedSubordinateUsers();
 359              }
 360              Vtiger_Cache::set('vtiger-'.$this->getRole().'-'.$currentUserRoleModel->get('allowassignedrecordsto'), 'accessibleusers',$accessibleUser);
 361          }
 362          return $accessibleUser;
 363      }
 364  
 365      /**
 366       * Function to get same level and subordinates Users
 367       * @return <array> Users
 368       */
 369  	public function getSameLevelUsersWithSubordinates(){
 370          $currentUserRoleModel = Settings_Roles_Record_Model::getInstanceById($this->getRole());
 371          $sameLevelRoles = $currentUserRoleModel->getSameLevelRoles();
 372          $sameLevelUsers = $this->getAllUsersOnRoles($sameLevelRoles);
 373          $subordinateUsers = $this->getRoleBasedSubordinateUsers();
 374          foreach ($subordinateUsers as $userId => $userName) {
 375              $sameLevelUsers[$userId] = $userName;
 376          }
 377          return $sameLevelUsers;
 378      }
 379      
 380      /**
 381       * Function to get subordinates Users
 382       * @return <array> Users
 383       */
 384  	public function getRoleBasedSubordinateUsers(){
 385          $currentUserRoleModel = Settings_Roles_Record_Model::getInstanceById($this->getRole());
 386          $childernRoles = $currentUserRoleModel->getAllChildren();
 387          $users = $this->getAllUsersOnRoles($childernRoles);
 388          $currentUserDetail = array($this->getId() => $this->get('first_name').' '.$this->get('last_name'));
 389          $users = $currentUserDetail + $users;
 390          return $users;
 391      }
 392  
 393      /**
 394       * Function to get the users based on Roles
 395       * @param type $roles
 396       * @return <array>
 397       */
 398  	public function getAllUsersOnRoles($roles) {
 399          $db = PearDatabase::getInstance();
 400          $roleIds = array();
 401          foreach ($roles as $key => $role) {
 402              $roleIds[] = $role->getId();
 403          }
 404          
 405          if(empty($roleIds)) {
 406              return array();
 407          }
 408          
 409          $sql = 'SELECT userid FROM vtiger_user2role WHERE roleid IN ('.  generateQuestionMarks($roleIds).')';
 410          $result = $db->pquery($sql, $roleIds);
 411          $noOfUsers = $db->num_rows($result);
 412          $userIds = array();
 413          $subUsers = array();
 414          if($noOfUsers > 0) {
 415              for($i=0; $i<$noOfUsers; ++$i) {
 416                  $userIds[] = $db->query_result($result, $i, 'userid');
 417              }
 418              $query = 'SELECT id, first_name, last_name FROM vtiger_users WHERE status = ? AND id IN ('.  generateQuestionMarks($userIds).')';
 419              $result = $db->pquery($query, array('ACTIVE', $userIds));
 420              $noOfUsers = $db->num_rows($result);
 421              for($j=0; $j<$noOfUsers; ++$j) {
 422                  $userId = $db->query_result($result, $j,'id');
 423                  $firstName = $db->query_result($result, $j, 'first_name');
 424                  $lastName = $db->query_result($result, $j, 'last_name');
 425                  $subUsers[$userId] = $firstName .' '.$lastName;
 426              }
 427          }
 428          return $subUsers;
 429      }
 430      
 431      /**
 432       * Function to get all the accessible groups
 433       * @return <Array>
 434       */
 435  	public function getAccessibleGroups($private="",$module = false) {
 436          //TODO:Remove dependence on $_REQUEST for the module name in the below API
 437          $accessibleGroups = Vtiger_Cache::get('vtiger-'.$private, 'accessiblegroups');
 438          if(!$accessibleGroups){
 439              $accessibleGroups = get_group_array(false, "ACTIVE", "", $private,$module);
 440              Vtiger_Cache::set('vtiger-'.$private, 'accessiblegroups',$accessibleGroups);
 441          }
 442          return get_group_array(false, "ACTIVE", "", $private);
 443      }
 444  
 445      /**
 446       * Function to get privillage model
 447       * @return $privillage model
 448       */
 449  	public function getPrivileges() {
 450          $privilegesModel = $this->get('privileges');
 451  
 452          if (empty($privilegesModel)) {
 453              $privilegesModel = Users_Privileges_Model::getInstanceById($this->getId());
 454              $this->set('privileges', $privilegesModel);
 455          }
 456  
 457          return $privilegesModel;
 458      }
 459  
 460      /**
 461       * Function to get user default activity view
 462       * @return <String>
 463       */
 464  	public function getActivityView() {
 465          $activityView = $this->get('activity_view');
 466          return $activityView;
 467      }
 468  
 469      /**
 470       * Function to delete corresponding image
 471       * @param <type> $imageId
 472       */
 473  	public function deleteImage($imageId) {
 474          $db = PearDatabase::getInstance();
 475  
 476          $checkResult = $db->pquery('SELECT smid FROM vtiger_salesmanattachmentsrel WHERE attachmentsid = ?', array($imageId));
 477          $smId = $db->query_result($checkResult, 0, 'smid');
 478  
 479          if ($this->getId() === $smId) {
 480              $db->pquery('DELETE FROM vtiger_attachments WHERE attachmentsid = ?', array($imageId));
 481              $db->pquery('DELETE FROM vtiger_salesmanattachmentsrel WHERE attachmentsid = ?', array($imageId));
 482              return true;
 483          }
 484          return false;
 485      }
 486  
 487  
 488      /**
 489       * Function to get the Day Starts picklist values
 490       * @param type $name Description
 491       */
 492  	public static function getDayStartsPicklistValues($stucturedValues){
 493          $fieldModel = $stucturedValues['LBL_CALENDAR_SETTINGS'];
 494          $hour_format = $fieldModel['hour_format']->getPicklistValues();
 495          $start_hour = $fieldModel['start_hour']->getPicklistValues();
 496  
 497          $defaultValues = array('00:00'=>'12:00 AM','01:00'=>'01:00 AM','02:00'=>'02:00 AM','03:00'=>'03:00 AM','04:00'=>'04:00 AM','05:00'=>'05:00 AM',
 498                      '06:00'=>'06:00 AM','07:00'=>'07:00 AM','08:00'=>'08:00 AM','09:00'=>'09:00 AM','10:00'=>'10:00 AM','11:00'=>'11:00 AM','12:00'=>'12:00 PM',
 499                      '13:00'=>'01:00 PM','14:00'=>'02:00 PM','15:00'=>'03:00 PM','16:00'=>'04:00 PM','17:00'=>'05:00 PM','18:00'=>'06:00 PM','19:00'=>'07:00 PM',
 500                      '20:00'=>'08:00 PM','21:00'=>'09:00 PM','22:00'=>'10:00 PM','23:00'=>'11:00 PM');
 501  
 502          $picklistDependencyData = array();
 503          foreach ($hour_format as $value) {
 504              if($value == 24){
 505                  $picklistDependencyData['hour_format'][$value]['start_hour'] = $start_hour;
 506              }else{
 507                  $picklistDependencyData['hour_format'][$value]['start_hour'] = $defaultValues;
 508              }
 509          }
 510          if(empty($picklistDependencyData['hour_format']['__DEFAULT__']['start_hour'])) {
 511              $picklistDependencyData['hour_format']['__DEFAULT__']['start_hour'] = $defaultValues;
 512          }
 513          return $picklistDependencyData;
 514      }
 515  
 516      /**
 517       * Function returns if tag cloud is enabled or not
 518       */
 519  	function getTagCloudStatus() {
 520          $db = PearDatabase::getInstance();
 521          $query = "SELECT visible FROM vtiger_homestuff WHERE userid=? AND stufftype='Tag Cloud'";
 522          $visibility = $db->query_result($db->pquery($query, array($this->getId())), 0, 'visible');
 523          if($visibility == 0) {
 524              return true;
 525          } 
 526          return false; 
 527      }
 528  
 529      /**
 530       * Function saves tag cloud
 531       */
 532  	function saveTagCloud() {
 533          $db = PearDatabase::getInstance();
 534          $db->pquery("UPDATE vtiger_homestuff SET visible = ? WHERE userid=? AND stufftype='Tag Cloud'",
 535                  array($this->get('tagcloud'), $this->getId()));
 536      }
 537  
 538      /**
 539       * Function to get user groups
 540       * @param type $userId
 541       * @return <array> - groupId's
 542       */
 543  	public static function getUserGroups($userId){
 544          $db = PearDatabase::getInstance();
 545          $groupIds = array();
 546          $query = "SELECT groupid FROM vtiger_users2group WHERE userid=?";
 547          $result = $db->pquery($query, array($userId));
 548          for($i=0; $i<$db->num_rows($result); $i++){
 549              $groupId = $db->query_result($result, $i, 'groupid');
 550              $groupIds[] = $groupId;
 551          }
 552          return $groupIds;
 553      }
 554  
 555      /**
 556       * Function returns the users activity reminder in seconds
 557       * @return string
 558       */
 559      /**
 560       * Function returns the users activity reminder in seconds
 561       * @return string
 562       */
 563  	function getCurrentUserActivityReminderInSeconds() {
 564          $activityReminder = $this->reminder_interval;
 565          $activityReminderInSeconds = '';
 566          if($activityReminder != 'None') {
 567              preg_match('/([0-9]+)[\s]([a-zA-Z]+)/', $activityReminder, $matches);
 568              if($matches) {
 569                  $number = $matches[1];
 570                  $string = $matches[2];
 571                  if($string) {
 572                      switch($string) {
 573                          case 'Minute':
 574                          case 'Minutes': $activityReminderInSeconds = $number * 60;            break;
 575                          case 'Hour'   : $activityReminderInSeconds = $number * 60 * 60;        break;
 576                          case 'Day'    : $activityReminderInSeconds = $number * 60 * 60 * 24;break;
 577                          default : $activityReminderInSeconds = '';
 578                      }
 579                  }
 580              }
 581          }
 582          return $activityReminderInSeconds;
 583      }    
 584      
 585      /**
 586       * Function to get the users count
 587       * @param <Boolean> $onlyActive - If true it returns count of only acive users else only inactive users
 588       * @return <Integer> number of users
 589       */
 590      public static function getCount($onlyActive = false) {
 591          $db = PearDatabase::getInstance();
 592          $query = 'SELECT 1 FROM vtiger_users ';
 593          $params = array();
 594          
 595          if($onlyActive) {
 596              $query.= ' WHERE status=? ';
 597              array_push($params,'active');
 598          }
 599  
 600          $result = $db->pquery($query,$params);
 601          
 602          $numOfUsers = $db->num_rows($result);
 603          return $numOfUsers;
 604      }
 605      
 606      /**
 607       * Funtion to get Duplicate Record Url
 608       * @return <String>
 609       */
 610  	public function getDuplicateRecordUrl() {
 611          $module = $this->getModule();
 612          return 'index.php?module='.$this->getModuleName().'&parent=Settings&view='.$module->getEditViewName().'&record='.$this->getId().'&isDuplicate=true';
 613  
 614      }
 615      
 616      /**
 617       * Function to get instance of user model by name
 618       * @param <String> $userName
 619       * @return <Users_Record_Model>
 620       */
 621  	public static function getInstanceByName($userName) {
 622          $db = PearDatabase::getInstance();
 623          $result = $db->pquery('SELECT id FROM vtiger_users WHERE user_name = ?', array($userName));
 624  
 625          if ($db->num_rows($result)) {
 626              return Users_Record_Model::getInstanceById($db->query_result($result, 0, 'id'), 'Users');
 627          }
 628          return false;
 629      }
 630      
 631      /**
 632       * Function to delete the current Record Model
 633       */
 634  	public function delete() {
 635          $this->getModule()->deleteRecord($this);
 636      }
 637      
 638          public function isAccountOwner() {
 639          $db = PearDatabase::getInstance();
 640          $query = 'SELECT is_owner FROM vtiger_users WHERE id = ?';
 641          $isOwner = $db->query_result($db->pquery($query, array($this->getId())), 0, 'is_owner');
 642          if($isOwner == 1) {
 643              return true;
 644          } 
 645          return false;
 646      }
 647      
 648  	public function getActiveAdminUsers() {
 649          $db = PearDatabase::getInstance();
 650  
 651          $sql = 'SELECT id FROM vtiger_users WHERE status=? AND is_admin=?';
 652          $result = $db->pquery($sql, array('ACTIVE', 'on'));
 653  
 654          $noOfUsers = $db->num_rows($result);
 655          $users = array();
 656          if($noOfUsers > 0) {
 657              $focus = new Users();
 658              for($i=0; $i<$noOfUsers; ++$i) {
 659                  $userId = $db->query_result($result, $i, 'id');
 660                  $focus->id = $userId;
 661                  $focus->retrieve_entity_info($userId, 'Users');
 662  
 663                  $userModel = self::getInstanceFromUserObject($focus);
 664                  $users[$userModel->getId()] = $userModel;
 665              }
 666          }
 667          return $users;
 668      }
 669      
 670  	public function isFirstTimeLogin($userId) {
 671          $db = PearDatabase::getInstance();
 672  
 673          $query = 'SELECT 1 FROM vtiger_crmsetup WHERE userid = ? and setup_status = ?';
 674          $result = $db->pquery($query, array($userId, 1));
 675          if($db->num_rows($result) == 0){
 676              return true;
 677          }
 678          return false;
 679      }
 680      
 681      /**
 682       * Function to get the user hash
 683       * @param type $userId
 684       * @return boolean
 685       */
 686  	public function getUserHash() {
 687          $db = PearDatabase::getInstance();
 688          $query = 'SELECT user_hash FROM vtiger_users WHERE id = ?';
 689          $result = $db->pquery($query, array($this->getId()));
 690          if($db->num_rows($result) > 0){
 691              return $db->query_result($result, 0, 'user_hash');
 692              
 693          }
 694          }
 695          
 696          /*
 697           * Function to delete user permanemtly from CRM and
 698           * assign all record which are assigned to that user
 699           * and not transfered to other user to other user
 700           * 
 701           * @param User Ids of user to be deleted and user
 702           * to whom records should be assigned
 703           */
 704          public function deleteUserPermanently($userId, $newOwnerId) {
 705                  $db = PearDatabase::getInstance();
 706                  
 707                  $sql = "UPDATE vtiger_crmentity SET smcreatorid=?,smownerid=? WHERE smcreatorid=? AND setype=?";
 708                  $db->pquery($sql, array($newOwnerId, $newOwnerId, $userId,'ModComments'));
 709                  
 710                  //update history details in vtiger_modtracker_basic 
 711                  $sql ="update vtiger_modtracker_basic set whodid=? where whodid=?"; 
 712                  $db->pquery($sql, array($newOwnerId, $userId)); 
 713  
 714                  //update comments details in vtiger_modcomments 
 715                  $sql ="update vtiger_modcomments set userid=? where userid=?"; 
 716                  $db->pquery($sql, array($newOwnerId, $userId));
 717  
 718                  $sql = "DELETE FROM vtiger_users WHERE id=?";
 719                  $db->pquery($sql, array($userId));
 720                  
 721          }
 722      
 723      /**
 724       * Function to get the Display Name for the record
 725       * @return <String> - Entity Display Name for the record
 726       */
 727  	public function getDisplayName() {
 728          return getFullNameFromArray($this->getModuleName(),$this->getData());
 729      }
 730  }


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