PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/branch/vtigercrm-530-540-patch-original/modules/Users/Users.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 1455 lines | 990 code | 232 blank | 233 comment | 215 complexity | b58c6950723899e541f86bb44ca2eabf MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*********************************************************************************
  3. * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
  4. * ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  8. * the specific language governing rights and limitations under the License.
  9. * The Original Code is: SugarCRM Open Source
  10. * The Initial Developer of the Original Code is SugarCRM, Inc.
  11. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12. * All Rights Reserved.
  13. * Contributor(s): ______________________________________.
  14. ********************************************************************************/
  15. /*********************************************
  16. * With modifications by
  17. * Daniel Jabbour
  18. * iWebPress Incorporated, www.iwebpress.com
  19. * djabbour - a t - iwebpress - d o t - com
  20. ********************************************/
  21. /*********************************************************************************
  22. * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Users/Users.php,v 1.10 2005/04/19 14:40:48 ray Exp $
  23. * Description: TODO: To be written.
  24. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  25. * All Rights Reserved.
  26. * Contributor(s): ______________________________________..
  27. ********************************************************************************/
  28. require_once('include/logging.php');
  29. require_once('include/database/PearDatabase.php');
  30. require_once('include/utils/UserInfoUtil.php');
  31. require_once 'data/CRMEntity.php';
  32. require_once('modules/Calendar/Activity.php');
  33. require_once('modules/Contacts/Contacts.php');
  34. require_once('data/Tracker.php');
  35. require_once 'include/utils/CommonUtils.php';
  36. require_once 'include/Webservices/Utils.php';
  37. require_once('modules/Users/UserTimeZonesArray.php');
  38. // User is used to store customer information.
  39. /** Main class for the user module
  40. *
  41. */
  42. class Users extends CRMEntity {
  43. var $log;
  44. /**
  45. * @var PearDatabase
  46. */
  47. var $db;
  48. // Stored fields
  49. var $id;
  50. var $authenticated = false;
  51. var $error_string;
  52. var $is_admin;
  53. var $deleted;
  54. var $tab_name = Array('vtiger_users','vtiger_attachments','vtiger_user2role','vtiger_asteriskextensions');
  55. var $tab_name_index = Array('vtiger_users'=>'id','vtiger_attachments'=>'attachmentsid','vtiger_user2role'=>'userid','vtiger_asteriskextensions'=>'userid');
  56. var $table_name = "vtiger_users";
  57. var $table_index= 'id';
  58. // This is the list of fields that are in the lists.
  59. var $list_link_field= 'last_name';
  60. var $list_mode;
  61. var $popup_type;
  62. var $search_fields = Array(
  63. 'Name'=>Array('vtiger_users'=>'last_name'),
  64. 'Email'=>Array('vtiger_users'=>'email1'),
  65. 'Email2'=>Array('vtiger_users'=>'email2')
  66. );
  67. var $search_fields_name = Array(
  68. 'Name'=>'last_name',
  69. 'Email'=>'email1',
  70. 'Email2'=>'email2'
  71. );
  72. var $module_name = "Users";
  73. var $object_name = "User";
  74. var $user_preferences;
  75. var $homeorder_array = array('HDB','ALVT','PLVT','QLTQ','CVLVT','HLT','GRT','OLTSO','ILTI','MNL','OLTPO','LTFAQ', 'UA', 'PA');
  76. var $encodeFields = Array("first_name", "last_name", "description");
  77. // This is used to retrieve related fields from form posts.
  78. var $additional_column_fields = Array('reports_to_name');
  79. var $sortby_fields = Array('status','email1','email2','phone_work','is_admin','user_name','last_name');
  80. // This is the list of vtiger_fields that are in the lists.
  81. var $list_fields = Array(
  82. 'First Name'=>Array('vtiger_users'=>'first_name'),
  83. 'Last Name'=>Array('vtiger_users'=>'last_name'),
  84. 'Role Name'=>Array('vtiger_user2role'=>'roleid'),
  85. 'User Name'=>Array('vtiger_users'=>'user_name'),
  86. 'Status'=>Array('vtiger_users'=>'status'),
  87. 'Email'=>Array('vtiger_users'=>'email1'),
  88. 'Email2'=>Array('vtiger_users'=>'email2'),
  89. 'Admin'=>Array('vtiger_users'=>'is_admin'),
  90. 'Phone'=>Array('vtiger_users'=>'phone_work')
  91. );
  92. var $list_fields_name = Array(
  93. 'Last Name'=>'last_name',
  94. 'First Name'=>'first_name',
  95. 'Role Name'=>'roleid',
  96. 'User Name'=>'user_name',
  97. 'Status'=>'status',
  98. 'Email'=>'email1',
  99. 'Email2'=>'email2',
  100. 'Admin'=>'is_admin',
  101. 'Phone'=>'phone_work'
  102. );
  103. //Default Fields for Email Templates -- Pavani
  104. var $emailTemplate_defaultFields = array('first_name','last_name','title','department','phone_home','phone_mobile','signature','email1','email2','address_street','address_city','address_state','address_country','address_postalcode');
  105. var $popup_fields = array('last_name');
  106. // This is the list of fields that are in the lists.
  107. var $default_order_by = "user_name";
  108. var $default_sort_order = 'ASC';
  109. var $record_id;
  110. var $new_schema = true;
  111. var $DEFAULT_PASSWORD_CRYPT_TYPE; //'BLOWFISH', /* before PHP5.3*/ MD5;
  112. /** constructor function for the main user class
  113. instantiates the Logger class and PearDatabase Class
  114. *
  115. */
  116. function Users() {
  117. $this->log = LoggerManager::getLogger('user');
  118. $this->log->debug("Entering Users() method ...");
  119. $this->db = PearDatabase::getInstance();
  120. $this->DEFAULT_PASSWORD_CRYPT_TYPE = (version_compare(PHP_VERSION, '5.3.0') >= 0)?
  121. 'PHP5.3MD5': 'MD5';
  122. $this->column_fields = getColumnFields('Users');
  123. $this->column_fields['ccurrency_name'] = '';
  124. $this->column_fields['currency_code'] = '';
  125. $this->column_fields['currency_symbol'] = '';
  126. $this->column_fields['conv_rate'] = '';
  127. $this->log->debug("Exiting Users() method ...");
  128. }
  129. // Mike Crowe Mod --------------------------------------------------------Default ordering for us
  130. /**
  131. * Function to get sort order
  132. * return string $sorder - sortorder string either 'ASC' or 'DESC'
  133. */
  134. function getSortOrder() {
  135. global $log;
  136. $log->debug("Entering getSortOrder() method ...");
  137. if(isset($_REQUEST['sorder']))
  138. $sorder = $this->db->sql_escape_string($_REQUEST['sorder']);
  139. else
  140. $sorder = (($_SESSION['USERS_SORT_ORDER'] != '')?($_SESSION['USERS_SORT_ORDER']):($this->default_sort_order));
  141. $log->debug("Exiting getSortOrder method ...");
  142. return $sorder;
  143. }
  144. /**
  145. * Function to get order by
  146. * return string $order_by - fieldname(eg: 'subject')
  147. */
  148. function getOrderBy() {
  149. global $log;
  150. $log->debug("Entering getOrderBy() method ...");
  151. $use_default_order_by = '';
  152. if(PerformancePrefs::getBoolean('LISTVIEW_DEFAULT_SORTING', true)) {
  153. $use_default_order_by = $this->default_order_by;
  154. }
  155. if (isset($_REQUEST['order_by']))
  156. $order_by = $this->db->sql_escape_string($_REQUEST['order_by']);
  157. else
  158. $order_by = (($_SESSION['USERS_ORDER_BY'] != '')?($_SESSION['USERS_ORDER_BY']):($use_default_order_by));
  159. $log->debug("Exiting getOrderBy method ...");
  160. return $order_by;
  161. }
  162. // Mike Crowe Mod --------------------------------------------------------
  163. /** Function to set the user preferences in the session
  164. * @param $name -- name:: Type varchar
  165. * @param $value -- value:: Type varchar
  166. *
  167. */
  168. function setPreference($name, $value) {
  169. if(!isset($this->user_preferences)) {
  170. if(isset($_SESSION["USER_PREFERENCES"]))
  171. $this->user_preferences = $_SESSION["USER_PREFERENCES"];
  172. else
  173. $this->user_preferences = array();
  174. }
  175. if(!array_key_exists($name,$this->user_preferences )|| $this->user_preferences[$name] != $value) {
  176. $this->log->debug("Saving To Preferences:". $name."=".$value);
  177. $this->user_preferences[$name] = $value;
  178. $this->savePreferecesToDB();
  179. }
  180. $_SESSION[$name] = $value;
  181. }
  182. /** Function to save the user preferences to db
  183. *
  184. */
  185. function savePreferecesToDB() {
  186. $data = base64_encode(serialize($this->user_preferences));
  187. $query = "UPDATE $this->table_name SET user_preferences=? where id=?";
  188. $result =& $this->db->pquery($query, array($data, $this->id));
  189. $this->log->debug("SAVING: PREFERENCES SIZE ". strlen($data)."ROWS AFFECTED WHILE UPDATING USER PREFERENCES:".$this->db->getAffectedRowCount($result));
  190. $_SESSION["USER_PREFERENCES"] = $this->user_preferences;
  191. }
  192. /** Function to load the user preferences from db
  193. *
  194. */
  195. function loadPreferencesFromDB($value) {
  196. if(isset($value) && !empty($value)) {
  197. $this->log->debug("LOADING :PREFERENCES SIZE ". strlen($value));
  198. $this->user_preferences = unserialize(base64_decode($value));
  199. $_SESSION = array_merge($this->user_preferences, $_SESSION);
  200. $this->log->debug("Finished Loading");
  201. $_SESSION["USER_PREFERENCES"] = $this->user_preferences;
  202. }
  203. }
  204. /**
  205. * @return string encrypted password for storage in DB and comparison against DB password.
  206. * @param string $user_name - Must be non null and at least 2 characters
  207. * @param string $user_password - Must be non null and at least 1 character.
  208. * @desc Take an unencrypted username and password and return the encrypted password
  209. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  210. * All Rights Reserved..
  211. * Contributor(s): ______________________________________..
  212. */
  213. function encrypt_password($user_password, $crypt_type='') {
  214. // encrypt the password.
  215. $salt = substr($this->column_fields["user_name"], 0, 2);
  216. // Fix for: http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/4923
  217. if($crypt_type == '') {
  218. // Try to get the crypt_type which is in database for the user
  219. $crypt_type = $this->get_user_crypt_type();
  220. }
  221. // For more details on salt format look at: http://in.php.net/crypt
  222. if($crypt_type == 'MD5') {
  223. $salt = '$1$' . $salt . '$';
  224. } elseif($crypt_type == 'BLOWFISH') {
  225. $salt = '$2$' . $salt . '$';
  226. } elseif($crypt_type == 'PHP5.3MD5') {
  227. //only change salt for php 5.3 or higher version for backward
  228. //compactibility.
  229. //crypt API is lot stricter in taking the value for salt.
  230. $salt = '$1$' . str_pad($salt, 9, '0');
  231. }
  232. $encrypted_password = crypt($user_password, $salt);
  233. return $encrypted_password;
  234. }
  235. /** Function to authenticate the current user with the given password
  236. * @param $password -- password::Type varchar
  237. * @returns true if authenticated or false if not authenticated
  238. */
  239. function authenticate_user($password) {
  240. $usr_name = $this->column_fields["user_name"];
  241. $query = "SELECT * from $this->table_name where user_name=? AND user_hash=?";
  242. $params = array($usr_name, $password);
  243. $result = $this->db->requirePsSingleResult($query, $params, false);
  244. if(empty($result)) {
  245. $this->log->fatal("SECURITY: failed login by $usr_name");
  246. return false;
  247. }
  248. return true;
  249. }
  250. /** Function for validation check
  251. *
  252. */
  253. function validation_check($validate, $md5, $alt='') {
  254. $validate = base64_decode($validate);
  255. if(file_exists($validate) && $handle = fopen($validate, 'rb', true)) {
  256. $buffer = fread($handle, filesize($validate));
  257. if(md5($buffer) == $md5 || (!empty($alt) && md5($buffer) == $alt)) {
  258. return 1;
  259. }
  260. return -1;
  261. }else {
  262. return -1;
  263. }
  264. }
  265. /** Function for authorization check
  266. *
  267. */
  268. function authorization_check($validate, $authkey, $i) {
  269. $validate = base64_decode($validate);
  270. $authkey = base64_decode($authkey);
  271. if(file_exists($validate) && $handle = fopen($validate, 'rb', true)) {
  272. $buffer = fread($handle, filesize($validate));
  273. if(substr_count($buffer, $authkey) < $i)
  274. return -1;
  275. }else {
  276. return -1;
  277. }
  278. }
  279. /**
  280. * Checks the config.php AUTHCFG value for login type and forks off to the proper module
  281. *
  282. * @param string $user_password - The password of the user to authenticate
  283. * @return true if the user is authenticated, false otherwise
  284. */
  285. function doLogin($user_password) {
  286. global $AUTHCFG;
  287. $usr_name = $this->column_fields["user_name"];
  288. switch (strtoupper($AUTHCFG['authType'])) {
  289. case 'LDAP':
  290. $this->log->debug("Using LDAP authentication");
  291. require_once('modules/Users/authTypes/LDAP.php');
  292. $result = ldapAuthenticate($this->column_fields["user_name"], $user_password);
  293. if ($result == NULL) {
  294. return false;
  295. } else {
  296. return true;
  297. }
  298. break;
  299. case 'AD':
  300. $this->log->debug("Using Active Directory authentication");
  301. require_once('modules/Users/authTypes/adLDAP.php');
  302. $adldap = new adLDAP();
  303. if ($adldap->authenticate($this->column_fields["user_name"],$user_password)) {
  304. return true;
  305. } else {
  306. return false;
  307. }
  308. break;
  309. default:
  310. $this->log->debug("Using integrated/SQL authentication");
  311. $query = "SELECT crypt_type FROM $this->table_name WHERE user_name=?";
  312. $result = $this->db->requirePsSingleResult($query, array($usr_name), false);
  313. if (empty($result)) {
  314. return false;
  315. }
  316. $crypt_type = $this->db->query_result($result, 0, 'crypt_type');
  317. $encrypted_password = $this->encrypt_password($user_password, $crypt_type);
  318. $query = "SELECT * from $this->table_name where user_name=? AND user_password=?";
  319. $result = $this->db->requirePsSingleResult($query, array($usr_name, $encrypted_password), false);
  320. if (empty($result)) {
  321. return false;
  322. } else {
  323. return true;
  324. }
  325. break;
  326. }
  327. return false;
  328. }
  329. /**
  330. * Load a user based on the user_name in $this
  331. * @return -- this if load was successul and null if load failed.
  332. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  333. * All Rights Reserved..
  334. * Contributor(s): ______________________________________..
  335. */
  336. function load_user($user_password) {
  337. $usr_name = $this->column_fields["user_name"];
  338. if(isset($_SESSION['loginattempts'])) {
  339. $_SESSION['loginattempts'] += 1;
  340. }else {
  341. $_SESSION['loginattempts'] = 1;
  342. }
  343. if($_SESSION['loginattempts'] > 5) {
  344. $this->log->warn("SECURITY: " . $usr_name . " has attempted to login ". $_SESSION['loginattempts'] . " times.");
  345. }
  346. $this->log->debug("Starting user load for $usr_name");
  347. if( !isset($this->column_fields["user_name"]) || $this->column_fields["user_name"] == "" || !isset($user_password) || $user_password == "")
  348. return null;
  349. $authCheck = false;
  350. $authCheck = $this->doLogin($user_password);
  351. if(!$authCheck) {
  352. $this->log->warn("User authentication for $usr_name failed");
  353. return null;
  354. }
  355. // Get the fields for the user
  356. $query = "SELECT * from $this->table_name where user_name='$usr_name'";
  357. $result = $this->db->requireSingleResult($query, false);
  358. $row = $this->db->fetchByAssoc($result);
  359. $this->column_fields = $row;
  360. $this->id = $row['id'];
  361. $user_hash = strtolower(md5($user_password));
  362. // If there is no user_hash is not present or is out of date, then create a new one.
  363. if(!isset($row['user_hash']) || $row['user_hash'] != $user_hash) {
  364. $query = "UPDATE $this->table_name SET user_hash=? where id=?";
  365. $this->db->pquery($query, array($user_hash, $row['id']), true, "Error setting new hash for {$row['user_name']}: ");
  366. }
  367. $this->loadPreferencesFromDB($row['user_preferences']);
  368. if ($row['status'] != "Inactive") $this->authenticated = true;
  369. unset($_SESSION['loginattempts']);
  370. return $this;
  371. }
  372. /**
  373. * Get crypt type to use for password for the user.
  374. * Fix for: http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/4923
  375. */
  376. function get_user_crypt_type() {
  377. $crypt_res = null;
  378. $crypt_type = $this->DEFAULT_PASSWORD_CRYPT_TYPE;
  379. // For backward compatability, we need to make sure to handle this case.
  380. global $adb;
  381. $table_cols = $adb->getColumnNames("vtiger_users");
  382. if(!in_array("crypt_type", $table_cols)) {
  383. return $crypt_type;
  384. }
  385. if(isset($this->id)) {
  386. // Get the type of crypt used on password before actual comparision
  387. $qcrypt_sql = "SELECT crypt_type from $this->table_name where id=?";
  388. $crypt_res = $this->db->pquery($qcrypt_sql, array($this->id), true);
  389. } else if(isset($this->column_fields["user_name"])) {
  390. $qcrypt_sql = "SELECT crypt_type from $this->table_name where user_name=?";
  391. $crypt_res = $this->db->pquery($qcrypt_sql, array($this->column_fields["user_name"]));
  392. } else {
  393. $crypt_type = $this->DEFAULT_PASSWORD_CRYPT_TYPE;
  394. }
  395. if($crypt_res && $this->db->num_rows($crypt_res)) {
  396. $crypt_row = $this->db->fetchByAssoc($crypt_res);
  397. $crypt_type = $crypt_row['crypt_type'];
  398. }
  399. return $crypt_type;
  400. }
  401. /**
  402. * @param string $user name - Must be non null and at least 1 character.
  403. * @param string $user_password - Must be non null and at least 1 character.
  404. * @param string $new_password - Must be non null and at least 1 character.
  405. * @return boolean - If passwords pass verification and query succeeds, return true, else return false.
  406. * @desc Verify that the current password is correct and write the new password to the DB.
  407. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  408. * All Rights Reserved..
  409. * Contributor(s): ______________________________________..
  410. */
  411. function change_password($user_password, $new_password, $dieOnError = true) {
  412. $usr_name = $this->column_fields["user_name"];
  413. global $mod_strings;
  414. global $current_user;
  415. $this->log->debug("Starting password change for $usr_name");
  416. if( !isset($new_password) || $new_password == "") {
  417. $this->error_string = $mod_strings['ERR_PASSWORD_CHANGE_FAILED_1'].$user_name.$mod_strings['ERR_PASSWORD_CHANGE_FAILED_2'];
  418. return false;
  419. }
  420. if (!is_admin($current_user)) {
  421. $this->db->startTransaction();
  422. if(!$this->verifyPassword($user_password)) {
  423. $this->log->warn("Incorrect old password for $usr_name");
  424. $this->error_string = $mod_strings['ERR_PASSWORD_INCORRECT_OLD'];
  425. return false;
  426. }
  427. if($this->db->hasFailedTransaction()) {
  428. if($dieOnError) {
  429. die("error verifying old transaction[".$this->db->database->ErrorNo()."] ".
  430. $this->db->database->ErrorMsg());
  431. }
  432. return false;
  433. }
  434. }
  435. $user_hash = strtolower(md5($new_password));
  436. //set new password
  437. $crypt_type = $this->DEFAULT_PASSWORD_CRYPT_TYPE;
  438. $encrypted_new_password = $this->encrypt_password($new_password, $crypt_type);
  439. $query = "UPDATE $this->table_name SET user_password=?, confirm_password=?, user_hash=?, ".
  440. "crypt_type=? where id=?";
  441. $this->db->startTransaction();
  442. $this->db->pquery($query, array($encrypted_new_password, $encrypted_new_password,
  443. $user_hash, $crypt_type, $this->id));
  444. if($this->db->hasFailedTransaction()) {
  445. if($dieOnError) {
  446. die("error setting new password: [".$this->db->database->ErrorNo()."] ".
  447. $this->db->database->ErrorMsg());
  448. }
  449. return false;
  450. }
  451. return true;
  452. }
  453. function de_cryption($data) {
  454. require_once('include/utils/encryption.php');
  455. $de_crypt = new Encryption();
  456. if(isset($data)) {
  457. $decrypted_password = $de_crypt->decrypt($data);
  458. }
  459. return $decrypted_password;
  460. }
  461. function changepassword($newpassword) {
  462. require_once('include/utils/encryption.php');
  463. $en_crypt = new Encryption();
  464. if( isset($newpassword)) {
  465. $encrypted_password = $en_crypt->encrypt($newpassword);
  466. }
  467. return $encrypted_password;
  468. }
  469. function verifyPassword($password) {
  470. $query = "SELECT user_name,user_password,crypt_type FROM {$this->table_name} WHERE id=?";
  471. $result =$this->db->pquery($query, array($this->id));
  472. $row = $this->db->fetchByAssoc($result);
  473. $this->log->debug("select old password query: $query");
  474. $this->log->debug("return result of $row");
  475. $encryptedPassword = $this->encrypt_password($password, $row['crypt_type']);
  476. if($encryptedPassword != $row['user_password']) {
  477. return false;
  478. }
  479. return true;
  480. }
  481. function is_authenticated() {
  482. return $this->authenticated;
  483. }
  484. /** gives the user id for the specified user name
  485. * @param $user_name -- user name:: Type varchar
  486. * @returns user id
  487. */
  488. function retrieve_user_id($user_name) {
  489. global $adb;
  490. $query = "SELECT id from vtiger_users where user_name=? AND deleted=0";
  491. $result =$adb->pquery($query, array($user_name));
  492. $userid = $adb->query_result($result,0,'id');
  493. return $userid;
  494. }
  495. /**
  496. * @return -- returns a list of all users in the system.
  497. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  498. * All Rights Reserved..
  499. * Contributor(s): ______________________________________..
  500. */
  501. function verify_data() {
  502. $usr_name = $this->column_fields["user_name"];
  503. global $mod_strings;
  504. $query = "SELECT user_name from vtiger_users where user_name=? AND id<>? AND deleted=0";
  505. $result =$this->db->pquery($query, array($usr_name, $this->id), true, "Error selecting possible duplicate users: ");
  506. $dup_users = $this->db->fetchByAssoc($result);
  507. $query = "SELECT user_name from vtiger_users where is_admin = 'on' AND deleted=0";
  508. $result =$this->db->pquery($query, array(), true, "Error selecting possible duplicate vtiger_users: ");
  509. $last_admin = $this->db->fetchByAssoc($result);
  510. $this->log->debug("last admin length: ".count($last_admin));
  511. $this->log->debug($last_admin['user_name']." == ".$usr_name);
  512. $verified = true;
  513. if($dup_users != null) {
  514. $this->error_string .= $mod_strings['ERR_USER_NAME_EXISTS_1'].$usr_name.''.$mod_strings['ERR_USER_NAME_EXISTS_2'];
  515. $verified = false;
  516. }
  517. if(!isset($_REQUEST['is_admin']) &&
  518. count($last_admin) == 1 &&
  519. $last_admin['user_name'] == $usr_name) {
  520. $this->log->debug("last admin length: ".count($last_admin));
  521. $this->error_string .= $mod_strings['ERR_LAST_ADMIN_1'].$usr_name.$mod_strings['ERR_LAST_ADMIN_2'];
  522. $verified = false;
  523. }
  524. return $verified;
  525. }
  526. /** Function to return the column name array
  527. *
  528. */
  529. function getColumnNames_User() {
  530. $mergeflds = array("FIRSTNAME","LASTNAME","USERNAME","SECONDARYEMAIL","TITLE","OFFICEPHONE","DEPARTMENT",
  531. "MOBILE","OTHERPHONE","FAX","EMAIL",
  532. "HOMEPHONE","OTHEREMAIL","PRIMARYADDRESS",
  533. "CITY","STATE","POSTALCODE","COUNTRY");
  534. return $mergeflds;
  535. }
  536. function fill_in_additional_list_fields() {
  537. $this->fill_in_additional_detail_fields();
  538. }
  539. function fill_in_additional_detail_fields() {
  540. $query = "SELECT u1.first_name, u1.last_name from vtiger_users u1, vtiger_users u2 where u1.id = u2.reports_to_id AND u2.id = ? and u1.deleted=0";
  541. $result =$this->db->pquery($query, array($this->id), true, "Error filling in additional detail vtiger_fields") ;
  542. $row = $this->db->fetchByAssoc($result);
  543. $this->log->debug("additional detail query results: $row");
  544. if($row != null) {
  545. $this->reports_to_name = stripslashes(getFullNameFromArray('Users', $row));
  546. }
  547. else {
  548. $this->reports_to_name = '';
  549. }
  550. }
  551. /** Function to get the current user information from the user_privileges file
  552. * @param $userid -- user id:: Type integer
  553. * @returns user info in $this->column_fields array:: Type array
  554. *
  555. */
  556. function retrieveCurrentUserInfoFromFile($userid) {
  557. require('user_privileges/user_privileges_'.$userid.'.php');
  558. foreach($this->column_fields as $field=>$value_iter) {
  559. if(isset($user_info[$field])) {
  560. $this->$field = $user_info[$field];
  561. $this->column_fields[$field] = $user_info[$field];
  562. }
  563. }
  564. $this->id = $userid;
  565. return $this;
  566. }
  567. /** Function to save the user information into the database
  568. * @param $module -- module name:: Type varchar
  569. *
  570. */
  571. function saveentity($module) {
  572. global $current_user;//$adb added by raju for mass mailing
  573. $insertion_mode = $this->mode;
  574. if(empty($this->column_fields['time_zone'])) {
  575. $dbDefaultTimeZone = DateTimeField::getDBTimeZone();
  576. $this->column_fields['time_zone'] = $dbDefaultTimeZone;
  577. $this->time_zone = $dbDefaultTimeZone;
  578. }
  579. if(empty($this->column_fields['currency_id'])) {
  580. $this->column_fields['currency_id'] = CurrencyField::getDBCurrencyId();
  581. }
  582. if(empty($this->column_fields['date_format'])) {
  583. $this->column_fields['date_format'] = 'yyyy-mm-dd';
  584. }
  585. $this->db->println("TRANS saveentity starts $module");
  586. $this->db->startTransaction();
  587. foreach($this->tab_name as $table_name) {
  588. if($table_name == 'vtiger_attachments') {
  589. $this->insertIntoAttachment($this->id,$module);
  590. }
  591. else {
  592. $this->insertIntoEntityTable($table_name, $module);
  593. }
  594. }
  595. require_once('modules/Users/CreateUserPrivilegeFile.php');
  596. createUserPrivilegesfile($this->id);
  597. unset($_SESSION['next_reminder_interval']);
  598. unset($_SESSION['next_reminder_time']);
  599. if($insertion_mode != 'edit') {
  600. $this->createAccessKey();
  601. }
  602. $this->db->completeTransaction();
  603. $this->db->println("TRANS saveentity ends");
  604. }
  605. function createAccessKey() {
  606. global $adb,$log;
  607. $log->info("Entering Into function createAccessKey()");
  608. $updateQuery = "update vtiger_users set accesskey=? where id=?";
  609. $insertResult = $adb->pquery($updateQuery,array(vtws_generateRandomAccessKey(16),$this->id));
  610. $log->info("Exiting function createAccessKey()");
  611. }
  612. /** Function to insert values in the specifed table for the specified module
  613. * @param $table_name -- table name:: Type varchar
  614. * @param $module -- module:: Type varchar
  615. */
  616. function insertIntoEntityTable($table_name, $module) {
  617. global $log;
  618. $log->info("function insertIntoEntityTable ".$module.' vtiger_table name ' .$table_name);
  619. global $adb, $current_user;
  620. $insertion_mode = $this->mode;
  621. //Checkin whether an entry is already is present in the vtiger_table to update
  622. if($insertion_mode == 'edit') {
  623. $check_query = "select * from ".$table_name." where ".$this->tab_name_index[$table_name]."=?";
  624. $check_result=$this->db->pquery($check_query, array($this->id));
  625. $num_rows = $this->db->num_rows($check_result);
  626. if($num_rows <= 0) {
  627. $insertion_mode = '';
  628. }
  629. }
  630. // We will set the crypt_type based on the insertion_mode
  631. $crypt_type = '';
  632. if($insertion_mode == 'edit') {
  633. $update = '';
  634. $update_params = array();
  635. $tabid= getTabid($module);
  636. $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3) and vtiger_field.presence in (0,2)";
  637. $params = array($tabid, $table_name);
  638. }
  639. else {
  640. $column = $this->tab_name_index[$table_name];
  641. if($column == 'id' && $table_name == 'vtiger_users') {
  642. $currentuser_id = $this->db->getUniqueID("vtiger_users");
  643. $this->id = $currentuser_id;
  644. }
  645. $qparams = array($this->id);
  646. $tabid= getTabid($module);
  647. $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)";
  648. $params = array($tabid, $table_name);
  649. $crypt_type = $this->DEFAULT_PASSWORD_CRYPT_TYPE;
  650. }
  651. $result = $this->db->pquery($sql, $params);
  652. $noofrows = $this->db->num_rows($result);
  653. for($i=0; $i<$noofrows; $i++) {
  654. $fieldname=$this->db->query_result($result,$i,"fieldname");
  655. $columname=$this->db->query_result($result,$i,"columnname");
  656. $uitype=$this->db->query_result($result,$i,"uitype");
  657. $typeofdata=$adb->query_result($result,$i,"typeofdata");
  658. $typeofdata_array = explode("~",$typeofdata);
  659. $datatype = $typeofdata_array[0];
  660. if(isset($this->column_fields[$fieldname])) {
  661. if($uitype == 56) {
  662. if($this->column_fields[$fieldname] === 'on' || $this->column_fields[$fieldname] == 1) {
  663. $fldvalue = 1;
  664. }
  665. else {
  666. $fldvalue = 0;
  667. }
  668. }elseif($uitype == 15) {
  669. if($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) {
  670. //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
  671. $sql="select $columname from $table_name where ".$this->tab_name_index[$table_name]."=?";
  672. $res = $adb->pquery($sql,array($this->id));
  673. $pick_val = $adb->query_result($res,0,$columname);
  674. $fldvalue = $pick_val;
  675. }
  676. else {
  677. $fldvalue = $this->column_fields[$fieldname];
  678. }
  679. }
  680. elseif($uitype == 33) {
  681. if(is_array($this->column_fields[$fieldname])) {
  682. $field_list = implode(' |##| ',$this->column_fields[$fieldname]);
  683. }else {
  684. $field_list = $this->column_fields[$fieldname];
  685. }
  686. $fldvalue = $field_list;
  687. }
  688. elseif($uitype == 99) {
  689. $fldvalue = $this->encrypt_password($this->column_fields[$fieldname], $crypt_type);
  690. }
  691. else {
  692. $fldvalue = $this->column_fields[$fieldname];
  693. $fldvalue = stripslashes($fldvalue);
  694. }
  695. $fldvalue = from_html($fldvalue,($insertion_mode == 'edit')?true:false);
  696. }
  697. else {
  698. $fldvalue = '';
  699. }
  700. if($uitype == 31) {
  701. $themeList = get_themes();
  702. if(!in_array($fldvalue, $themeList) || $fldvalue == '') {
  703. global $default_theme;
  704. if(!empty($default_theme) && in_array($default_theme, $themeList)) {
  705. $fldvalue = $default_theme;
  706. } else {
  707. $fldvalue = $themeList[0];
  708. }
  709. }
  710. if($current_user->id == $this->id) {
  711. $_SESSION['vtiger_authenticated_user_theme'] = $fldvalue;
  712. }
  713. } elseif($uitype == 32) {
  714. $languageList = Vtiger_Language::getAll();
  715. $languageList = array_keys($languageList);
  716. if(!in_array($fldvalue, $languageList) || $fldvalue == '') {
  717. global $default_language;
  718. if(!empty($default_language) && in_array($default_language, $languageList)) {
  719. $fldvalue = $default_language;
  720. } else {
  721. $fldvalue = $languageList[0];
  722. }
  723. }
  724. if($current_user->id == $this->id) {
  725. $_SESSION['authenticated_user_language'] = $fldvalue;
  726. }
  727. }
  728. if($fldvalue=='') {
  729. $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
  730. //$fldvalue =null;
  731. }
  732. if($insertion_mode == 'edit') {
  733. if($i == 0) {
  734. $update = $columname."=?";
  735. }
  736. else {
  737. $update .= ', '.$columname."=?";
  738. }
  739. array_push($update_params, $fldvalue);
  740. }
  741. else {
  742. $column .= ", ".$columname;
  743. array_push($qparams, $fldvalue);
  744. }
  745. }
  746. if($insertion_mode == 'edit') {
  747. //Check done by Don. If update is empty the the query fails
  748. if(trim($update) != '') {
  749. $sql1 = "update $table_name set $update where ".$this->tab_name_index[$table_name]."=?";
  750. array_push($update_params, $this->id);
  751. $this->db->pquery($sql1, $update_params);
  752. }
  753. }
  754. else {
  755. // Set the crypt_type being used, to override the DB default constraint as it is not in vtiger_field
  756. if($table_name == 'vtiger_users' && strpos('crypt_type', $column) === false) {
  757. $column .= ', crypt_type';
  758. $qparams[]= $crypt_type;
  759. }
  760. // END
  761. $sql1 = "insert into $table_name ($column) values(". generateQuestionMarks($qparams) .")";
  762. $this->db->pquery($sql1, $qparams);
  763. }
  764. }
  765. /** Function to insert values into the attachment table
  766. * @param $id -- entity id:: Type integer
  767. * @param $module -- module:: Type varchar
  768. */
  769. function insertIntoAttachment($id,$module) {
  770. global $log;
  771. $log->debug("Entering into insertIntoAttachment($id,$module) method.");
  772. foreach($_FILES as $fileindex => $files) {
  773. if($files['name'] != '' && $files['size'] > 0) {
  774. $files['original_name'] = vtlib_purify($_REQUEST[$fileindex.'_hidden']);
  775. $this->uploadAndSaveFile($id,$module,$files);
  776. }
  777. }
  778. $log->debug("Exiting from insertIntoAttachment($id,$module) method.");
  779. }
  780. /** Function to retreive the user info of the specifed user id The user info will be available in $this->column_fields array
  781. * @param $record -- record id:: Type integer
  782. * @param $module -- module:: Type varchar
  783. */
  784. function retrieve_entity_info($record, $module) {
  785. global $adb,$log;
  786. $log->debug("Entering into retrieve_entity_info($record, $module) method.");
  787. if($record == '') {
  788. $log->debug("record is empty. returning null");
  789. return null;
  790. }
  791. $result = Array();
  792. foreach($this->tab_name_index as $table_name=>$index) {
  793. $result[$table_name] = $adb->pquery("select * from ".$table_name." where ".$index."=?", array($record));
  794. }
  795. $tabid = getTabid($module);
  796. $sql1 = "select * from vtiger_field where tabid=? and vtiger_field.presence in (0,2)";
  797. $result1 = $adb->pquery($sql1, array($tabid));
  798. $noofrows = $adb->num_rows($result1);
  799. for($i=0; $i<$noofrows; $i++) {
  800. $fieldcolname = $adb->query_result($result1,$i,"columnname");
  801. $tablename = $adb->query_result($result1,$i,"tablename");
  802. $fieldname = $adb->query_result($result1,$i,"fieldname");
  803. $fld_value = $adb->query_result($result[$tablename],0,$fieldcolname);
  804. $this->column_fields[$fieldname] = $fld_value;
  805. $this->$fieldname = $fld_value;
  806. }
  807. $this->column_fields["record_id"] = $record;
  808. $this->column_fields["record_module"] = $module;
  809. $currency_query = "select * from vtiger_currency_info where id=? and currency_status='Active' and deleted=0";
  810. $currency_result = $adb->pquery($currency_query, array($this->column_fields["currency_id"]));
  811. if($adb->num_rows($currency_result) == 0) {
  812. $currency_query = "select * from vtiger_currency_info where id =1";
  813. $currency_result = $adb->pquery($currency_query, array());
  814. }
  815. $currency_array = array("$"=>"&#36;","&euro;"=>"&#8364;","&pound;"=>"&#163;","&yen;"=>"&#165;");
  816. $ui_curr = $currency_array[$adb->query_result($currency_result,0,"currency_symbol")];
  817. if($ui_curr == "")
  818. $ui_curr = $adb->query_result($currency_result,0,"currency_symbol");
  819. $this->column_fields["currency_name"]= $this->currency_name = $adb->query_result($currency_result,0,"currency_name");
  820. $this->column_fields["currency_code"]= $this->currency_code = $adb->query_result($currency_result,0,"currency_code");
  821. $this->column_fields["currency_symbol"]= $this->currency_symbol = $ui_curr;
  822. $this->column_fields["conv_rate"]= $this->conv_rate = $adb->query_result($currency_result,0,"conversion_rate");
  823. // TODO - This needs to be cleaned up once default values for fields are picked up in a cleaner way.
  824. // This is just a quick fix to ensure things doesn't start breaking when the user currency configuration is missing
  825. if($this->column_fields['currency_grouping_pattern'] == ''
  826. && $this->column_fields['currency_symbol_placement'] == '') {
  827. $this->column_fields['currency_grouping_pattern'] = $this->currency_grouping_pattern = '123,456,789';
  828. $this->column_fields['currency_decimal_separator'] = $this->currency_decimal_separator = '.';
  829. $this->column_fields['currency_grouping_separator'] = $this->currency_grouping_separator = ',';
  830. $this->column_fields['currency_symbol_placement'] = $this->currency_symbol_placement = '$1.0';
  831. }
  832. // TODO - This needs to be cleaned up once default values for fields are picked up in a cleaner way.
  833. // This is just a quick fix to ensure things doesn't start breaking when the user currency configuration is missing
  834. if($this->column_fields['currency_grouping_pattern'] == ''
  835. && $this->column_fields['currency_symbol_placement'] == '') {
  836. $this->column_fields['currency_grouping_pattern'] = $this->currency_grouping_pattern = '123,456,789';
  837. $this->column_fields['currency_decimal_separator'] = $this->currency_decimal_separator = '.';
  838. $this->column_fields['currency_grouping_separator'] = $this->currency_grouping_separator = ',';
  839. $this->column_fields['currency_symbol_placement'] = $this->currency_symbol_placement = '$1.0';
  840. }
  841. $this->id = $record;
  842. $log->debug("Exit from retrieve_entity_info($record, $module) method.");
  843. return $this;
  844. }
  845. /** Function to upload the file to the server and add the file details in the attachments table
  846. * @param $id -- user id:: Type varchar
  847. * @param $module -- module name:: Type varchar
  848. * @param $file_details -- file details array:: Type array
  849. */
  850. function uploadAndSaveFile($id,$module,$file_details) {
  851. global $log;
  852. $log->debug("Entering into uploadAndSaveFile($id,$module,$file_details) method.");
  853. global $current_user;
  854. global $upload_badext;
  855. $date_var = date('Y-m-d H:i:s');
  856. //to get the owner id
  857. $ownerid = $this->column_fields['assigned_user_id'];
  858. if(!isset($ownerid) || $ownerid=='')
  859. $ownerid = $current_user->id;
  860. $file = $file_details['name'];
  861. $binFile = sanitizeUploadFileName($file, $upload_badext);
  862. $filename = ltrim(basename(" ".$binFile)); //allowed filename like UTF-8 characters
  863. $filetype= $file_details['type'];
  864. $filesize = $file_details['size'];
  865. $filetmp_name = $file_details['tmp_name'];
  866. $current_id = $this->db->getUniqueID("vtiger_crmentity");
  867. //get the file path inwhich folder we want to upload the file
  868. $upload_file_path = decideFilePath();
  869. //upload the file in server
  870. $upload_status = move_uploaded_file($filetmp_name,$upload_file_path.$current_id."_".$binFile);
  871. $save_file = 'true';
  872. //only images are allowed for these modules
  873. if($module == 'Users') {
  874. $save_file = validateImageFile($file_details);
  875. }
  876. if($save_file == 'true') {
  877. $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?,?,?,?,?,?,?)";
  878. $params1 = array($current_id, $current_user->id, $ownerid, $module." Attachment", $this->column_fields['description'], $this->db->formatString("vtiger_crmentity","createdtime",$date_var), $this->db->formatDate($date_var, true));
  879. $this->db->pquery($sql1, $params1);
  880. $sql2="insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?,?,?,?,?)";
  881. $params2 = array($current_id, $filename, $this->column_fields['description'], $filetype, $upload_file_path);
  882. $result=$this->db->pquery($sql2, $params2);
  883. if($id != '') {
  884. $delquery = 'delete from vtiger_salesmanattachmentsrel where smid = ?';
  885. $this->db->pquery($delquery, array($id));
  886. }
  887. $sql3='insert into vtiger_salesmanattachmentsrel values(?,?)';
  888. $this->db->pquery($sql3, array($id, $current_id));
  889. //we should update the imagename in the users table
  890. $this->db->pquery("update vtiger_users set imagename=? where id=?", array($filename, $id));
  891. }
  892. else {
  893. $log->debug("Skip the save attachment process.");
  894. }
  895. $log->debug("Exiting from uploadAndSaveFile($id,$module,$file_details) method.");
  896. return;
  897. }
  898. /** Function to save the user information into the database
  899. * @param $module -- module name:: Type varchar
  900. *
  901. */
  902. function save($module_name) {
  903. global $log, $adb;
  904. //Save entity being called with the modulename as parameter
  905. $this->saveentity($module_name);
  906. // Added for Reminder Popup support
  907. $query_prev_interval = $adb->pquery("SELECT reminder_interval from vtiger_users where id=?",
  908. array($this->id));
  909. $prev_reminder_interval = $adb->query_result($query_prev_interval,0,'reminder_interval');
  910. //$focus->imagename = $image_upload_array['imagename'];
  911. $this->saveHomeStuffOrder($this->id);
  912. SaveTagCloudView($this->id);
  913. // Added for Reminder Popup support
  914. $this->resetReminderInterval($prev_reminder_interval);
  915. //Creating the Privileges Flat File
  916. if(isset($this->column_fields['roleid'])) {
  917. updateUser2RoleMapping($this->column_fields['roleid'],$this->id);
  918. }
  919. require_once('modules/Users/CreateUserPrivilegeFile.php');
  920. createUserPrivilegesfile($this->id);
  921. createUserSharingPrivilegesfile($this->id);
  922. }
  923. /**
  924. * gives the order in which the modules have to be displayed in the home page for the specified user id
  925. * @param $id -- user id:: Type integer
  926. * @returns the customized home page order in $return_array
  927. */
  928. function getHomeStuffOrder($id) {
  929. global $adb;
  930. if(!is_array($this->homeorder_array)) {
  931. $this->homeorder_array = array('UA', 'PA', 'ALVT','HDB','PLVT','QLTQ','CVLVT','HLT',
  932. 'GRT','OLTSO','ILTI','MNL','OLTPO','LTFAQ');
  933. }
  934. $return_array = Array();
  935. $homeorder=Array();
  936. if($id != '') {
  937. $qry=" select distinct(vtiger_homedefault.hometype) from vtiger_homedefault inner join vtiger_homestuff on vtiger_homestuff.stuffid=vtiger_homedefault.stuffid where vtiger_homestuff.visible=0 and vtiger_homestuff.userid=?";
  938. $res=$adb->pquery($qry, array($id));
  939. for($q=0;$q<$adb->num_rows($res);$q++) {
  940. $homeorder[]=$adb->query_result($res,$q,"hometype");
  941. }
  942. for($i = 0;$i < count($this->homeorder_array);$i++) {
  943. if(in_array($this->homeorder_array[$i],$homeorder)) {
  944. $return_array[$this->homeorder_array[$i]] = $this->homeorder_array[$i];
  945. }else {
  946. $return_array[$this->homeorder_array[$i]] = '';
  947. }
  948. }
  949. }else {
  950. for($i = 0;$i < count($this->homeorder_array);$i++) {
  951. $return_array[$this->homeorder_array[$i]] = $this->homeorder_array[$i];
  952. }
  953. }
  954. return $return_array;
  955. }
  956. function getDefaultHomeModuleVisibility($home_string,$inVal) {
  957. $homeModComptVisibility=0;
  958. if($inVal == 'postinstall') {
  959. if($_REQUEST[$home_string] != '') {
  960. $homeModComptVisibility=0;
  961. }
  962. }
  963. return $homeModComptVisibility;
  964. }
  965. function insertUserdetails($inVal) {
  966. global $adb;
  967. $uid=$this->id;
  968. $s1=$adb->getUniqueID("vtiger_homestuff");
  969. $visibility=$this->getDefaultHomeModuleVisibility('ALVT',$inVal);
  970. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  971. $res=$adb->pquery($sql, array($s1,1,'Default',$uid,$visibility,'Top Accounts'));
  972. $s2=$adb->getUniqueID("vtiger_homestuff");
  973. $visibility=$this->getDefaultHomeModuleVisibility('HDB',$inVal);
  974. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  975. $res=$adb->pquery($sql, array($s2,2,'Default',$uid,$visibility,'Home Page Dashboard'));
  976. $s3=$adb->getUniqueID("vtiger_homestuff");
  977. $visibility=$this->getDefaultHomeModuleVisibility('PLVT',$inVal);
  978. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  979. $res=$adb->pquery($sql, array($s3,3,'Default',$uid,$visibility,'Top Potentials'));
  980. $s4=$adb->getUniqueID("vtiger_homestuff");
  981. $visibility=$this->getDefaultHomeModuleVisibility('QLTQ',$inVal);
  982. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  983. $res=$adb->pquery($sql, array($s4,4,'Default',$uid,$visibility,'Top Quotes'));
  984. $s5=$adb->getUniqueID("vtiger_homestuff");
  985. $visibility=$this->getDefaultHomeModuleVisibility('CVLVT',$inVal);
  986. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  987. $res=$adb->pquery($sql, array($s5,5,'Default',$uid,$visibility,'Key Metrics'));
  988. $s6=$adb->getUniqueID("vtiger_homestuff");
  989. $visibility=$this->getDefaultHomeModuleVisibility('HLT',$inVal);
  990. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  991. $res=$adb->pquery($sql, array($s6,6,'Default',$uid,$visibility,'Top Trouble Tickets'));
  992. $s7=$adb->getUniqueID("vtiger_homestuff");
  993. $visibility=$this->getDefaultHomeModuleVisibility('UA',$inVal);
  994. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  995. $res=$adb->pquery($sql, array($s7,7,'Default',$uid,$visibility,'Upcoming Activities'));
  996. $s8=$adb->getUniqueID("vtiger_homestuff");
  997. $visibility=$this->getDefaultHomeModuleVisibility('GRT',$inVal);
  998. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  999. $res=$adb->pquery($sql, array($s8,8,'Default',$uid,$visibility,'My Group Allocation'));
  1000. $s9=$adb->getUniqueID("vtiger_homestuff");
  1001. $visibility=$this->getDefaultHomeModuleVisibility('OLTSO',$inVal);
  1002. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  1003. $res=$adb->pquery($sql, array($s9,9,'Default',$uid,$visibility,'Top Sales Orders'));
  1004. $s10=$adb->getUniqueID("vtiger_homestuff");
  1005. $visibility=$this->getDefaultHomeModuleVisibility('ILTI',$inVal);
  1006. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  1007. $res=$adb->pquery($sql, array($s10,10,'Default',$uid,$visibility,'Top Invoices'));
  1008. $s11=$adb->getUniqueID("vtiger_homestuff");
  1009. $visibility=$this->getDefaultHomeModuleVisibility('MNL',$inVal);
  1010. $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)";
  1011. $res=$adb->pquery($sql, array($s11,11,'Default',$uid,$visibility,'My New Leads'));
  1012. $s12=$adb->getUniqueID("vtiger_homestuff");
  1013. $visibility=$this->getDefaultHomeModuleVisibility('OLTPO',$inVal);
  1014. $sql="insert into vtiger_homestuff val…

Large files files are truncated, but you can click here to view the full file