PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/chronique/SuppLoginSetup.php

http://chronique.googlecode.com/
PHP | 300 lines | 282 code | 13 blank | 5 comment | 3 complexity | 3bc44948fc6e737f387d16f5111727f4 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* $Id: SuppLoginSetup.php 4749 2011-11-21 09:22:06Z daintree $*/
  3. include('includes/session.inc');
  4. $title = _('Supplier Login Configuration');
  5. include('includes/header.inc');
  6. include('includes/SQL_CommonFunctions.inc');
  7. include ('includes/LanguagesArray.php');
  8. if (!isset($_SESSION['SupplierID'])){
  9. echo '<br />
  10. <br />';
  11. prnMsg(_('A supplier must first be selected before logins can be defined for it') . '<br /><br /><a href="' . $rootpath . '/SelectSupplier.php">' . _('Select A Supplier') . '</a>','info');
  12. include('includes/footer.inc');
  13. exit;
  14. }
  15. $ModuleList = array(_('Orders'),
  16. _('Receivables'),
  17. _('Payables'),
  18. _('Purchasing'),
  19. _('Inventory'),
  20. _('Manufacturing'),
  21. _('General Ledger'),
  22. _('Asset Manager'),
  23. _('Petty Cash'),
  24. _('Setup'));
  25. echo '<a href="' . $rootpath . '/SelectSupplier.php?">' . _('Back to Suppliers') . '</a><br />';
  26. echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Supplier') . '" alt="" />' . ' ' . _('Supplier') . ' : ' . $_SESSION['SupplierID'] . _(' has been selected') . '</p><br />';
  27. if (isset($_POST['submit'])) {
  28. //initialise no input errors assumed initially before we test
  29. $InputError = 0;
  30. /* actions to take once the user has clicked the submit button
  31. ie the page has called itself with some user input */
  32. //first off validate inputs sensible
  33. if (mb_strlen($_POST['UserID'])<4){
  34. $InputError = 1;
  35. prnMsg(_('The user ID entered must be at least 4 characters long'),'error');
  36. } elseif (ContainsIllegalCharacters($_POST['UserID'])) {
  37. $InputError = 1;
  38. prnMsg(_('User names cannot contain any of the following characters') . " - ' & + \" \\ " . _('or a space'),'error');
  39. } elseif (mb_strlen($_POST['Password'])<5){
  40. if (!$SelectedUser){
  41. $InputError = 1;
  42. prnMsg(_('The password entered must be at least 5 characters long'),'error');
  43. }
  44. } elseif (mb_strstr($_POST['Password'],$_POST['UserID'])!= False){
  45. $InputError = 1;
  46. prnMsg(_('The password cannot contain the user id'),'error');
  47. }
  48. /* Make a comma separated list of modules allowed ready to update the database*/
  49. $i=0;
  50. $ModulesAllowed = '';
  51. while ($i < count($ModuleList)){
  52. $FormVbl = 'Module_' . $i;
  53. $ModulesAllowed .= $_POST[($FormVbl)] . ',';
  54. $i++;
  55. }
  56. if ($InputError !=1) {
  57. $sql = "INSERT INTO www_users (userid,
  58. realname,
  59. supplierid,
  60. password,
  61. phone,
  62. email,
  63. pagesize,
  64. fullaccess,
  65. defaultlocation,
  66. lastvisitdate,
  67. modulesallowed,
  68. displayrecordsmax,
  69. theme,
  70. language)
  71. VALUES ('" . $_POST['UserID'] . "',
  72. '" . $_POST['RealName'] ."',
  73. '" . $_SESSION['SupplierID'] ."',
  74. '" . CryptPass($_POST['Password']) ."',
  75. '" . $_POST['Phone'] . "',
  76. '" . $_POST['Email'] ."',
  77. '" . $_POST['PageSize'] ."',
  78. '" . $_POST['Access'] . "',
  79. '" . $_POST['DefaultLocation'] ."',
  80. '" . date($_SESSION['DefaultDateFormat']) ."',
  81. '" . $ModulesAllowed . "',
  82. '" . $_SESSION['DefaultDisplayRecordsMax'] . "',
  83. '" . $_POST['Theme'] . "',
  84. '". $_POST['UserLanguage'] ."')";
  85. $ErrMsg = _('The user could not be added because');
  86. $DbgMsg = _('The SQL that was used to insert the new user and failed was');
  87. $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);
  88. prnMsg( _('A new supplier login has been created'), 'success' );
  89. include('includes/footer.inc');
  90. exit;
  91. }
  92. }
  93. echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '">';
  94. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  95. echo '<table class="selection">
  96. <tr>
  97. <td>' . _('User Login') . ':</td>
  98. <td><input type="text" name="UserID" size="22" maxlength="20" /></td>
  99. </tr>';
  100. if (!isset($_POST['Password'])) {
  101. $_POST['Password']='';
  102. }
  103. if (!isset($_POST['RealName'])) {
  104. $_POST['RealName']='';
  105. }
  106. if (!isset($_POST['Phone'])) {
  107. $_POST['Phone']='';
  108. }
  109. if (!isset($_POST['Email'])) {
  110. $_POST['Email']='';
  111. }
  112. echo '<tr>
  113. <td>' . _('Password') . ':</td>
  114. <td><input type="password" name="Password" size="22" maxlength="20" value="' . $_POST['Password'] . '">
  115. </tr>
  116. <tr>
  117. <td>' . _('Full Name') . ':</td>
  118. <td><input type="text" name="RealName" value="' . $_POST['RealName'] . '" size="36" maxlength="35" /></td>
  119. </tr>
  120. <tr>
  121. <td>' . _('Telephone No') . ':</td>
  122. <td><input type="text" name="Phone" value="' . $_POST['Phone'] . '" size="32" maxlength="30" /></td>
  123. </tr>
  124. <tr>
  125. <td>' . _('Email Address') .':</td>
  126. <td><input type="text" name="Email" value="' . $_POST['Email'] .'" size="32" maxlength="55" /></td>
  127. </tr>';
  128. //Make an array of the security roles where only one role is active and is ID 1
  129. //For the security role selection box, we will only show roles that have:
  130. //- Only one entry in securitygroups AND the tokenid of this entry == 9
  131. //First get all available security role ID's'
  132. $RolesResult = DB_query("SELECT secroleid FROM securityroles", $db);
  133. $FoundTheSupplierRole = false;
  134. while ($myroles = DB_fetch_array($RolesResult)){
  135. //Now look to find the tokens for the role - we just wnat the role that has just one token i.e. token 9
  136. $TokensResult = DB_query("SELECT tokenid
  137. FROM securitygroups
  138. WHERE secroleid = '" . $myroles['secroleid'] ."'",
  139. $db);
  140. if (DB_num_rows($TokensResult) == 1 ) {
  141. $mytoken = DB_fetch_row($TokensResult);
  142. if ($mytoken[0]==9){
  143. echo'<input type="hidden" name="Access" value ="' . $myroles['secroleid'] . '" />';
  144. $FoundTheSupplierRole = true;
  145. break;
  146. }
  147. }
  148. }
  149. if (!$FoundTheSupplierRole){
  150. prnMsg(_('The supplier login role is expected to contain just one token - number 9. There is no such role currently defined - so a supplier login cannot be set up until this role is defined'),'error');
  151. echo '</table>';
  152. include('includes/footer.inc');
  153. exit;
  154. }
  155. echo '<tr><td>' . _('Default Location') . ':</td>
  156. <td><select name="DefaultLocation">';
  157. $sql = "SELECT loccode, locationname FROM locations";
  158. $result = DB_query($sql,$db);
  159. while ($myrow=DB_fetch_array($result)){
  160. if (isset($_POST['DefaultLocation'])
  161. AND $myrow['loccode'] == $_POST['DefaultLocation']){
  162. echo '<option selected value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
  163. } else {
  164. echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
  165. }
  166. }
  167. echo '<tr><td>' . _('Reports Page Size') .':</td>
  168. <td><select name="PageSize">';
  169. if(isset($_POST['PageSize']) and $_POST['PageSize']=='A4'){
  170. echo '<option selected value="A4">' . _('A4') . '</option>';
  171. } else {
  172. echo '<option value="A4">' . _('A4') . '</option>';
  173. }
  174. if(isset($_POST['PageSize']) and $_POST['PageSize']=='A3'){
  175. echo '<option selected value="A3">' . _('A3') . '</option>';
  176. } else {
  177. echo '<option value="A3">' . _('A3') . '</option>';
  178. }
  179. if(isset($_POST['PageSize']) and $_POST['PageSize']=='A3_landscape'){
  180. echo '<option selected value="A3_landscape">' . _('A3') . ' ' . _('landscape') . '</option>';
  181. } else {
  182. echo '<option value="A3_landscape">' . _('A3') . ' ' . _('landscape') . '</option>';
  183. }
  184. if(isset($_POST['PageSize']) and $_POST['PageSize']=='letter'){
  185. echo '<option selected value="letter">' . _('Letter') . '</option>';
  186. } else {
  187. echo '<option value="letter">' . _('Letter') . '</option>';
  188. }
  189. if(isset($_POST['PageSize']) and $_POST['PageSize']=='letter_landscape'){
  190. echo '<option selected value="letter_landscape">' . _('Letter') . ' ' . _('landscape') . '</option>';
  191. } else {
  192. echo '<option value="letter_landscape">' . _('Letter') . ' ' . _('landscape') . '</option>';
  193. }
  194. if(isset($_POST['PageSize']) and $_POST['PageSize']=='legal'){
  195. echo '<option selected value="legal">' . _('Legal') . '</option>';
  196. } else {
  197. echo '<option Value="legal">' . _('Legal') . '</option>';
  198. }
  199. if(isset($_POST['PageSize']) and $_POST['PageSize']=='legal_landscape'){
  200. echo '<option selected value="legal_landscape">' . _('Legal') . ' ' . _('landscape') . '</option>';
  201. } else {
  202. echo '<option value="legal_landscape">' . _('Legal') . ' ' . _('landscape') . '</option>';
  203. }
  204. echo '</select></td></tr>';
  205. echo '<tr>
  206. <td>' . _('Theme') . ':</td>
  207. <td><select name="Theme">';
  208. $ThemeDirectory = dir('css/');
  209. while (false != ($ThemeName = $ThemeDirectory->read())){
  210. if (is_dir('css/' . $ThemeName) AND $ThemeName != '.' AND $ThemeName != '..' AND $ThemeName != '.svn'){
  211. if (isset($_POST['Theme']) and $_POST['Theme'] == $ThemeName){
  212. echo '<option selected value="' . $ThemeName . '">' . $ThemeName . '</option>';
  213. } else if (!isset($_POST['Theme']) and ($_SESSION['DefaultTheme']==$ThemeName)) {
  214. echo '<option selected value="' . $ThemeName . '">' . $ThemeName . '</option>';
  215. } else {
  216. echo '<option value="' . $ThemeName . '">' . $ThemeName . '</option>';
  217. }
  218. }
  219. }
  220. echo '</select></td></tr>';
  221. echo '<tr>
  222. <td>' . _('Language') . ':</td>
  223. <td><select name="UserLanguage">';
  224. foreach ($LanguagesArray as $LanguageEntry => $LanguageName){
  225. if (isset($_POST['UserLanguage']) and $_POST['UserLanguage'] == $LanguageEntry){
  226. echo '<option selected value="' . $LanguageEntry . '">' . $LanguageName['LanguageName'] .'</option>';
  227. } elseif (!isset($_POST['UserLanguage']) and $LanguageEntry == $DefaultLanguage) {
  228. echo '<option selected value="' . $LanguageEntry . '">' . $LanguageName['LanguageName'] .'</option>';
  229. } else {
  230. echo '<option value="' . $LanguageEntry . '">' . $LanguageName['LanguageName'] .'</option>';
  231. }
  232. }
  233. echo '</select></td>
  234. </tr>
  235. </table>
  236. <br />
  237. <div class="centre">
  238. <input type="submit" name="submit" value="' . _('Enter Information') . '" />
  239. </div>
  240. </form>';
  241. echo '<script type="text/javascript">defaultControl(document.forms[0].UserID);</script>';
  242. include('includes/footer.inc');
  243. ?>