PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/contents/member.inc.php

https://github.com/buitenzorg812/slims3-stable15-jquery
PHP | 292 lines | 198 code | 22 blank | 72 comment | 41 complexity | 5c2306224dbf6f86c4aac96cfaea7921 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. *
  4. * Member Area/Information
  5. * Copyright (C) 2009 Arie Nugraha (dicarve@yahoo.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. // required file
  23. require LIB_DIR.'member_logon.inc.php';
  24. // check if member already logged in
  25. $is_member_login = utility::isMemberLogin();
  26. $info = __('Welcome to Member\'s Area where you can view your current loan information and view your membership status.');
  27. // member's password changing flags
  28. define('CURR_PASSWD_WRONG', -1);
  29. define('PASSWD_NOT_MATCH', -2);
  30. define('CANT_UPDATE_PASSWD', -3);
  31. // if member is logged out
  32. if (isset($_GET['logout']) && $_GET['logout'] == '1') {
  33. // write log
  34. utility::writeLogs($dbs, 'member', $_SESSION['email'], 'Login', $_SESSION['member_name'].' Log Out from address '.$_SERVER['REMOTE_ADDR']);
  35. // completely destroy session cookie
  36. simbio_security::destroySessionCookie(null, SENAYAN_MEMBER_SESSION_COOKIES_NAME, SENAYAN_WEB_ROOT_DIR, false);
  37. header('Location: index.php?p=member');
  38. header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
  39. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  40. header('Pragma: no-cache');
  41. exit();
  42. }
  43. // if there is member login action
  44. if (isset($_POST['logMeIn']) && !$is_member_login) {
  45. $username = trim(strip_tags($_POST['memberID']));
  46. $password = trim(strip_tags($_POST['memberPassWord']));
  47. // check if username or password is empty
  48. if (!$username OR !$password) {
  49. echo '<div class="errorBox">'.__('Please fill your Username and Password to Login!').'</div>';
  50. } else {
  51. // regenerate session ID to prevent session hijacking
  52. session_regenerate_id(true);
  53. // create logon class instance
  54. $logon = new member_logon($username, $password, $sysconf['auth']['member']['method']);
  55. if ($sysconf['auth']['member']['method'] == 'ldap') {
  56. $ldap_configs = $sysconf['auth']['member'];
  57. }
  58. if ($logon->valid($dbs)) {
  59. // write log
  60. utility::writeLogs($dbs, 'member', $username, 'Login', 'Login success for member '.$username.' from address '.$_SERVER['REMOTE_ADDR']);
  61. header('Location: index.php?p=member');
  62. exit();
  63. } else {
  64. // write log
  65. utility::writeLogs($dbs, 'member', $username, 'Login', 'Login FAILED for member '.$username.' from address '.$_SERVER['REMOTE_ADDR']);
  66. // message
  67. $msg = '<div class="errorBox">'.__('Login FAILED! Wrong username or password!').'</div>';
  68. simbio_security::destroySessionCookie($msg, SENAYAN_MEMBER_SESSION_COOKIES_NAME, SENAYAN_WEB_ROOT_DIR, false);
  69. }
  70. }
  71. }
  72. // check if member already login
  73. if (!$is_member_login) {
  74. ?>
  75. <fieldset id="memberLogin">
  76. <legend><?php echo __('Library Member Login'); ?></legend>
  77. <div class="loginInfo"><?php echo __('Please insert your member ID and password given by library system administrator. If you are library\'s member and don\'t have a password yet, please contact library staff.'); ?></div>
  78. <form action="index.php?p=member" method="post">
  79. <div class="fieldLabel"><?php echo __('Member ID'); ?></div>
  80. <div><input type="text" name="memberID" /></div>
  81. <div class="fieldLabel marginTop"><?php echo __('Password'); ?></div>
  82. <div><input type="password" name="memberPassWord" /></div>
  83. <div class="marginTop"><input type="submit" name="logMeIn" value="<?php echo __('Login'); ?>" />
  84. </div>
  85. </form>
  86. </fieldset>
  87. <?php
  88. } else {
  89. /*
  90. * Function to show member change password form
  91. *
  92. * @return string
  93. */
  94. function changePassword()
  95. {
  96. // show the member information
  97. $_form = '<form id="memberChangePassword" method="post" action="index.php?p=member">'."\n";
  98. $_form .= '<table class="memberDetail" cellpadding="5" cellspacing="0">'."\n";
  99. $_form .= '<tr>'."\n";
  100. $_form .= '<td class="alterCell" width="20%"><strong>'.__('Current Password').'</strong></td>';
  101. $_form .= '<td class="alterCell2"><input type="password" name="currPass" /></td>';
  102. $_form .= '</tr>'."\n";
  103. $_form .= '<tr>'."\n";
  104. $_form .= '<td class="alterCell" width="20%"><strong>'.__('New Password').'</strong></td>';
  105. $_form .= '<td class="alterCell2"><input type="password" name="newPass" /></td>';
  106. $_form .= '</tr>'."\n";
  107. $_form .= '<tr>'."\n";
  108. $_form .= '<td class="alterCell" width="20%"><strong>'.__('Confirm Password').'</strong></td>';
  109. $_form .= '<td class="alterCell2"><input type="password" name="newPass2" /></td>';
  110. $_form .= '</tr>'."\n";
  111. $_form .= '<tr>'."\n";
  112. $_form .= '<td class="alterCell2" colspan="2"><input type="submit" name="changePass" value="'.__('Change Password').'" /></td>';
  113. $_form .= '</tr>'."\n";
  114. $_form .= '</table>'."\n";
  115. $_form .= '</form>'."\n";
  116. return $_form;
  117. }
  118. /*
  119. * Function to process member's password changes
  120. *
  121. * @param string $str_curr_pass = member's current password
  122. * @param string $str_new_pass = member's new password request
  123. * @param string $str_conf_new_pass = member's new password request confirmation
  124. * @return boolean true on success, false on failed
  125. */
  126. function procChangePassword($str_curr_pass, $str_new_pass, $str_conf_new_pass)
  127. {
  128. global $dbs;
  129. // current password checking
  130. $_sql_pass_check = sprintf('SELECT member_id FROM member
  131. WHERE mpasswd=MD5(\'%s\') AND member_id=\'%s\'',
  132. $dbs->escape_string(trim($str_curr_pass)), $dbs->escape_string(trim($_SESSION['mid'])));
  133. $_pass_check = $dbs->query($_sql_pass_check);
  134. if ($_pass_check->num_rows == 1) {
  135. $str_new_pass = trim($str_new_pass);
  136. $str_conf_new_pass = trim($str_conf_new_pass);
  137. // password confirmation check
  138. if ($str_new_pass && $str_conf_new_pass && ($str_new_pass === $str_conf_new_pass)) {
  139. $_sql_update_mpasswd = sprintf('UPDATE member SET mpasswd=MD5(\'%s\')
  140. WHERE member_id=\'%s\'', $dbs->escape_string($str_conf_new_pass), $dbs->escape_string(trim($_SESSION['mid'])));
  141. @$dbs->query($_sql_update_mpasswd);
  142. if (!$dbs->error) {
  143. return true;
  144. } else {
  145. return CANT_UPDATE_PASSWD;
  146. }
  147. } else {
  148. return PASSWD_NOT_MATCH;
  149. }
  150. } else {
  151. return CURR_PASSWD_WRONG;
  152. }
  153. }
  154. /*
  155. * Function to show membership detail of logged in member
  156. *
  157. * @return string
  158. */
  159. function showMemberDetail()
  160. {
  161. // show the member information
  162. $_detail = '<table class="memberDetail" cellpadding="5" cellspacing="0">'."\n";
  163. // member notes and pending information
  164. if ($_SESSION['m_membership_pending'] || $_SESSION['m_is_expired']) {
  165. $_detail .= '<tr>'."\n";
  166. $_detail .= '<td class="alterCell" width="15%"><strong>Notes</strong></td><td class="alterCell2" colspan="3">';
  167. if ($_SESSION['m_is_expired']) {
  168. $_detail .= '<div style="color: #f00;">'.__('Your Membership Already EXPIRED! Please extend your membership.').'</div>';
  169. }
  170. if ($_SESSION['m_membership_pending']) {
  171. $_detail .= '<div style="color: #f00;">'.__('Membership currently in pending state, no loan transaction can be made yet.').'</div>';
  172. }
  173. $_detail .= '</td>';
  174. $_detail .= '</tr>'."\n";
  175. }
  176. $_detail .= '<tr>'."\n";
  177. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Member Name').'</strong></td><td class="alterCell2" width="30%">'.$_SESSION['m_name'].'</td>';
  178. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Member ID').'</strong></td><td class="alterCell2" width="30%">'.$_SESSION['mid'].'</td>';
  179. $_detail .= '</tr>'."\n";
  180. $_detail .= '<tr>'."\n";
  181. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Member Email').'</strong></td><td class="alterCell2" width="30%">'.$_SESSION['m_email'].'</td>';
  182. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Member Type').'</strong></td><td class="alterCell2" width="30%">'.$_SESSION['m_member_type'].'</td>';
  183. $_detail .= '</tr>'."\n";
  184. $_detail .= '<tr>'."\n";
  185. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Register Date').'</strong></td><td class="alterCell2" width="30%">'.$_SESSION['m_register_date'].'</td>';
  186. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Expiry Date').'</strong></td><td class="alterCell2" width="30%">'.$_SESSION['m_expire_date'].'</td>';
  187. $_detail .= '</tr>'."\n";
  188. $_detail .= '<tr>'."\n";
  189. $_detail .= '<td class="alterCell" width="15%"><strong>'.__('Institution').'</strong></td>'
  190. .'<td class="alterCell2" colspan="3">'.$_SESSION['m_institution'].'</td>';
  191. $_detail .= '</tr>'."\n";
  192. $_detail .= '</table>'."\n";
  193. return $_detail;
  194. }
  195. /* callback function to show overdue */
  196. function showOverdue($obj_db, $array_data)
  197. {
  198. $_curr_date = date('Y-m-d');
  199. if (simbio_date::compareDates($array_data[3], $_curr_date) == $_curr_date) {
  200. return '<strong style="color: #f00;">'.$array_data[3].' '.__('OVERDUED').'</strong>';
  201. } else {
  202. return $array_data[3];
  203. }
  204. }
  205. /*
  206. * Function to show list of logged in member loan
  207. *
  208. * @param int number of loan records to show
  209. * @return string
  210. */
  211. function showLoanList($num_recs_show = 20)
  212. {
  213. global $dbs;
  214. require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
  215. require SIMBIO_BASE_DIR.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  216. require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging.inc.php';
  217. require SIMBIO_BASE_DIR.'simbio_UTILS/simbio_date.inc.php';
  218. // table spec
  219. $_table_spec = 'loan AS l
  220. LEFT JOIN member AS m ON l.member_id=m.member_id
  221. LEFT JOIN item AS i ON l.item_code=i.item_code
  222. LEFT JOIN biblio AS b ON i.biblio_id=b.biblio_id';
  223. // create datagrid
  224. $_loan_list = new simbio_datagrid();
  225. $_loan_list->setSQLColumn('l.item_code AS \''.__('Item Code').'\'',
  226. 'b.title AS \''.__('Title').'\'',
  227. 'l.loan_date AS \''.__('Loan Date').'\'',
  228. 'l.due_date AS \''.__('Due Date').'\'');
  229. $_loan_list->setSQLorder('l.loan_date DESC');
  230. $_criteria = sprintf('m.member_id=\'%s\' AND l.is_lent=1 AND is_return=0 ', $_SESSION['mid']);
  231. $_loan_list->setSQLCriteria($_criteria);
  232. // modify column value
  233. $_loan_list->modifyColumnContent(3, 'callback{showOverdue}');
  234. // set table and table header attributes
  235. $_loan_list->table_attr = 'align="center" class="memberLoanList" cellpadding="5" cellspacing="0"';
  236. $_loan_list->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  237. $_loan_list->using_AJAX = false;
  238. // return the result
  239. $_result = $_loan_list->createDataGrid($dbs, $_table_spec, $num_recs_show);
  240. $_result = '<div class="memberLoanListInfo">'.$_loan_list->num_rows.' '.__('item(s) currently on loan').'</div>'."\n".$_result;
  241. return $_result;
  242. }
  243. // if there is change password request
  244. if ($is_member_login && isset($_POST['changePass']) && $sysconf['auth']['member']['method'] == 'native') {
  245. $change_pass = procChangePassword($_POST['currPass'], $_POST['newPass'], $_POST['newPass2']);
  246. if ($change_pass === true) {
  247. $info = '<span style="font-size: 120%; font-weight: bold;">'.__('Your password have been changed successfully.').'</span>';
  248. } else {
  249. if ($change_pass === CURR_PASSWD_WRONG) {
  250. $info = __('Current password entered WRONG! Please insert the right password!');
  251. } else if ($change_pass === PASSWD_NOT_MATCH) {
  252. $info = __('Password confirmation FAILED! Make sure to check undercase or uppercase letters!');
  253. } else {
  254. $info = __('Password update FAILED! ERROR ON DATABASE!');
  255. }
  256. $info = '<span style="font-size: 120%; font-weight: bold; color: red;">'.$info.'</span>';
  257. }
  258. }
  259. // show all
  260. echo '<h3 class="memberInfoHead">'.__('Member Detail').'</h3>'."\n";
  261. echo showMemberDetail();
  262. echo '<h3 class="memberInfoHead">'.__('Your Current Loan').'</h3>'."\n";
  263. echo showLoanList();
  264. // change password only form NATIVE authentication, not for others such as LDAP
  265. if ($sysconf['auth']['member']['method'] == 'native') {
  266. echo '<h3 class="memberInfoHead">'.__('Change Password').'</h3>'."\n";
  267. echo changePassword();
  268. }
  269. }
  270. ?>