| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 3 /********************************************************************************* 4 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 5 * ("License"); You may not use this file except in compliance with the License 6 * The Original Code is: vtiger CRM Open Source 7 * The Initial Developer of the Original Code is vtiger. 8 * Portions created by vtiger are Copyright (C) vtiger. 9 * All Rights Reserved. 10 * 11 ********************************************************************************/ 12 13 include_once ('config.php'); 14 require_once ('include/logging.php'); 15 require_once ('data/SugarBean.php'); 16 require_once ('include/logging.php'); 17 require_once ('include/ListView/ListView.php'); 18 require_once ('include/database/PearDatabase.php'); 19 20 /** This class is used to store and display the login history of all the Users. 21 * An Admin User can view his login history details and of all the other users as well. 22 * StandardUser is allowed to view only his login history details. 23 **/ 24 class LoginHistory { 25 var $log; 26 var $db; 27 28 // Stored vtiger_fields 29 var $login_id; 30 var $user_name; 31 var $user_ip; 32 var $login_time; 33 var $logout_time; 34 var $status; 35 var $module_name = "Users"; 36 37 var $table_name = "vtiger_loginhistory"; 38 39 var $object_name = "LoginHistory"; 40 41 var $new_schema = true; 42 43 var $column_fields = Array("id" 44 ,"login_id" 45 ,"user_name" 46 ,"user_ip" 47 ,"login_time" 48 ,"logout_time" 49 ,"status" 50 ); 51 52 function LoginHistory() { 53 $this->log = LoggerManager::getLogger('loginhistory'); 54 $this->db = new PearDatabase(); 55 } 56 57 var $sortby_fields = Array('user_name', 'user_ip', 'login_time', 'logout_time', 'status'); 58 59 // This is the list of vtiger_fields that are in the lists. 60 var $list_fields = Array( 61 'User Name'=>Array('vtiger_loginhistory'=>'user_name'), 62 'User IP'=>Array('vtiger_loginhistory'=>'user_ip'), 63 'Signin Time'=>Array('vtiger_loginhistory'=>'login_time'), 64 'Signout Time'=>Array('vtiger_loginhistory'=>'logout_time'), 65 'Status'=>Array('vtiger_loginhistory'=>'status'), 66 ); 67 68 var $list_fields_name = Array( 69 'User Name'=>'user_name', 70 'User IP'=>'user_ip', 71 'Signin Time'=>'login_time', 72 'Signout Time'=>'logout_time', 73 'Status'=>'status' 74 ); 75 var $default_order_by = "login_time"; 76 var $default_sort_order = 'DESC'; 77 78 /** 79 * Function to get the Header values of Login History. 80 * Returns Header Values like UserName, IP, LoginTime etc in an array format. 81 **/ 82 function getHistoryListViewHeader() 83 { 84 global $log; 85 $log->debug("Entering getHistoryListViewHeader method ..."); 86 global $app_strings; 87 88 $header_array = array($app_strings['LBL_LIST_USER_NAME'], $app_strings['LBL_LIST_USERIP'], $app_strings['LBL_LIST_SIGNIN'], $app_strings['LBL_LIST_SIGNOUT'], $app_strings['LBL_LIST_STATUS']); 89 90 $log->debug("Exiting getHistoryListViewHeader method ..."); 91 return $header_array; 92 93 } 94 95 /** 96 * Function to get the Login History values of the User. 97 * @param $navigation_array - Array values to navigate through the number of entries. 98 * @param $sortorder - DESC 99 * @param $orderby - login_time 100 * Returns the login history entries in an array format. 101 **/ 102 function getHistoryListViewEntries($username, $navigation_array, $sorder='', $orderby='') 103 { 104 global $log; 105 $log->debug("Entering getHistoryListViewEntries() method ..."); 106 global $adb, $current_user; 107 108 if($sorder != '' && $order_by != '') 109 $list_query = "Select * from vtiger_loginhistory where user_name='".$username."' order by ".$order_by." ".$sorder; 110 else 111 $list_query = "Select * from vtiger_loginhistory where user_name='".$username."' order by ".$this->default_order_by." ".$this->default_sort_order; 112 113 114 $result = $adb->query($list_query); 115 $entries_list = array(); 116 117 if($navigation_array['end_val'] != 0) 118 { 119 for($i = $navigation_array['start']; $i <= $navigation_array['end_val']; $i++) 120 { 121 $entries = array(); 122 $loginid = $adb->query_result($result, $i-1, 'login_id'); 123 124 $entries[] = $adb->query_result($result, $i-1, 'user_name'); 125 $entries[] = $adb->query_result($result, $i-1, 'user_ip'); 126 $entries[] = $adb->query_result($result, $i-1, 'login_time'); 127 $entries[] = $adb->query_result($result, $i-1, 'logout_time'); 128 $entries[] = $adb->query_result($result, $i-1, 'status'); 129 130 $entries_list[] = $entries; 131 } 132 $log->debug("Exiting getHistoryListViewEntries() method ..."); 133 return $entries_list; 134 } 135 } 136 137 /** Function that Records the Login info of the User 138 * @param ref variable $usname :: Type varchar 139 * @param ref variable $usip :: Type varchar 140 * @param ref variable $intime :: Type timestamp 141 * Returns the query result which contains the details of User Login Info 142 */ 143 function user_login(&$usname,&$usip,&$intime) 144 { 145 $query = "Insert into vtiger_loginhistory (user_name, user_ip, logout_time, login_time, status) values ('$usname','$usip',null,".$this->db->formatDate($intime).",'Signed in')"; 146 $result = $this->db->query($query) 147 or die("MySQL error: ".mysql_error()); 148 149 return $result; 150 } 151 152 /** Function that Records the Logout info of the User 153 * @param ref variable $usname :: Type varchar 154 * @param ref variable $usip :: Type varchar 155 * @param ref variable $outime :: Type timestamp 156 * Returns the query result which contains the details of User Logout Info 157 */ 158 function user_logout(&$usname,&$usip,&$outtime) 159 { 160 $logid_qry = "SELECT max(login_id) AS login_id from vtiger_loginhistory where user_name='$usname' and user_ip='$usip'"; 161 $result = $this->db->query($logid_qry); 162 $loginid = $this->db->query_result($result,0,"login_id"); 163 if ($loginid == '') 164 { 165 return; 166 } 167 // update the user login info. 168 $query = "Update vtiger_loginhistory set logout_time =".$this->db->formatDate($outtime).", status='Signed off' where login_id = $loginid"; 169 $result = $this->db->query($query) 170 or die("MySQL error: ".mysql_error()); 171 } 172 173 /** Function to create list query 174 * @param reference variable - order by is passed when the query is executed 175 * @param reference variable - where condition is passed when the query is executed 176 * Returns Query. 177 */ 178 function create_list_query(&$order_by, &$where) 179 { 180 // Determine if the vtiger_account name is present in the where clause. 181 global $current_user; 182 $query = "SELECT user_name,user_ip, status, 183 ".$this->db->getDBDateString("login_time")." AS login_time, 184 ".$this->db->getDBDateString("logout_time")." AS logout_time 185 FROM ".$this->table_name; 186 if($where != "") 187 { 188 if(!is_admin($current_user)) 189 $where .=" AND user_name = '".$current_user->user_name."'"; 190 $query .= " WHERE ($where)"; 191 } 192 else 193 { 194 if(!is_admin($current_user)) 195 $query .= " WHERE user_name = '".$current_user->user_name."'"; 196 } 197 198 if(!empty($order_by)) 199 $query .= " ORDER BY $order_by"; 200 201 return $query; 202 } 203 204 } 205 206 207 208 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |