PageRenderTime 26ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Users/Profiles.php

https://gitlab.com/gregtyka/opensis
PHP | 258 lines | 206 code | 18 blank | 34 comment | 34 complexity | 37c811bf14807120d16e0e2df9caa836 MD5 | raw file
  1. <?php
  2. #**************************************************************************
  3. # openSIS is a free student information system for public and non-public
  4. # schools from Open Solutions for Education, Inc. It is web-based,
  5. # open source, and comes packed with features that include student
  6. # demographic info, scheduling, grade book, attendance,
  7. # report cards, eligibility, transcripts, parent portal,
  8. # student portal and more.
  9. #
  10. # Visit the openSIS web site at http://www.opensis.com to learn more.
  11. # If you have question regarding this system or the license, please send
  12. # an email to info@os4ed.com.
  13. #
  14. # Copyright (C) 2007-2008, Open Solutions for Education, Inc.
  15. #
  16. #*************************************************************************
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, version 2 of the License. See license.txt.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. #**************************************************************************
  29. DrawBC("Users >> ".ProgramTitle());
  30. include 'Menu.php';
  31. if($_REQUEST['profile_id']!='')
  32. {
  33. $exceptions_RET = DBGet(DBQuery("SELECT PROFILE_ID,MODNAME,CAN_USE,CAN_EDIT FROM PROFILE_EXCEPTIONS WHERE PROFILE_ID='$_REQUEST[profile_id]'"),array(),array('MODNAME'));
  34. $profile_RET = DBGet(DBQuery("SELECT PROFILE FROM USER_PROFILES WHERE ID='$_REQUEST[profile_id]'"));
  35. $xprofile = $profile_RET[1]['PROFILE'];
  36. if($xprofile=='student')
  37. {
  38. $xprofile = 'parent';
  39. unset($menu['Users']);
  40. }
  41. }
  42. if($_REQUEST['modfunc']=='delete' && AllowEdit())
  43. {
  44. $profile_RET = DBGet(DBQuery("SELECT TITLE FROM USER_PROFILES WHERE ID='$_REQUEST[profile_id]'"));
  45. if(Prompt('Confirm Delete','Are you sure you want to delete the user profile <i>'.$profile_RET[1]['TITLE'].'</i>?','Users of that profile will retain their permissions as a custom set which can be modified on a per-user basis through the User Permissions program.'))
  46. {
  47. DBQuery("DELETE FROM USER_PROFILES WHERE ID='".$_REQUEST['profile_id']."'");
  48. DBQuery("DELETE FROM STAFF_EXCEPTIONS WHERE USER_ID IN (SELECT STAFF_ID FROM STAFF WHERE PROFILE_ID='".$_REQUEST['profile_id']."')");
  49. DBQuery("INSERT INTO STAFF_EXCEPTIONS (USER_ID,MODNAME,CAN_USE,CAN_EDIT) SELECT s.STAFF_ID,e.MODNAME,e.CAN_USE,e.CAN_EDIT FROM STAFF s,PROFILE_EXCEPTIONS e WHERE s.PROFILE_ID='$_REQUEST[profile_id]' AND s.PROFILE_ID=e.PROFILE_ID");
  50. DBQuery("DELETE FROM PROFILE_EXCEPTIONS WHERE PROFILE_ID='".$_REQUEST['profile_id']."'");
  51. unset($_REQUEST['modfunc']);
  52. unset($_REQUEST['profile_id']);
  53. }
  54. }
  55. if($_REQUEST['modfunc']=='update' && AllowEdit() && !$_REQUEST['new_profile_title'])
  56. {
  57. $tmp_menu = $menuprof;
  58. $categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STUDENT_FIELD_CATEGORIES"));
  59. foreach($categories_RET as $category)
  60. {
  61. $file = 'Students/Student.php&category_id='.$category['ID'];
  62. $tmp_menu['Students'][$xprofile][$file] = ' &nbsp; &nbsp; &rsaquo; '.$category['TITLE'];
  63. }
  64. $categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STAFF_FIELD_CATEGORIES"));
  65. foreach($categories_RET as $category)
  66. {
  67. $file = 'Users/User.php&category_id='.$category['ID'];
  68. $tmp_menu['Users'][$xprofile][$file] = ' &nbsp; &nbsp; &rsaquo; '.$category['TITLE'];
  69. }
  70. foreach($tmp_menu as $modcat=>$profiles)
  71. {
  72. $values = $profiles[$xprofile];
  73. foreach($values as $modname=>$title)
  74. {
  75. if(!is_numeric($modname))
  76. {
  77. if(!count($exceptions_RET[$modname]) && ($_REQUEST['can_edit'][str_replace('.','_',$modname)] || $_REQUEST['can_use'][str_replace('.','_',$modname)]))
  78. DBQuery("INSERT INTO PROFILE_EXCEPTIONS (PROFILE_ID,MODNAME) values('$_REQUEST[profile_id]','$modname')");
  79. elseif(count($exceptions_RET[$modname]) && !$_REQUEST['can_edit'][str_replace('.','_',$modname)] && !$_REQUEST['can_use'][str_replace('.','_',$modname)])
  80. DBQuery("DELETE FROM PROFILE_EXCEPTIONS WHERE PROFILE_ID='$_REQUEST[profile_id]' AND MODNAME='$modname'");
  81. if($_REQUEST['can_edit'][str_replace('.','_',$modname)] || $_REQUEST['can_use'][str_replace('.','_',$modname)])
  82. {
  83. $update = "UPDATE PROFILE_EXCEPTIONS SET ";
  84. if($_REQUEST['can_edit'][str_replace('.','_',$modname)])
  85. $update .= "CAN_EDIT='Y',";
  86. else
  87. $update .= "CAN_EDIT=NULL,";
  88. if($_REQUEST['can_use'][str_replace('.','_',$modname)])
  89. $update .= "CAN_USE='Y'";
  90. else
  91. $update .= "CAN_USE=NULL";
  92. $update .= " WHERE PROFILE_ID='$_REQUEST[profile_id]' AND MODNAME='$modname';";
  93. DBQuery($update);
  94. }
  95. }
  96. }
  97. }
  98. $exceptions_RET = DBGet(DBQuery("SELECT MODNAME,CAN_USE,CAN_EDIT FROM PROFILE_EXCEPTIONS WHERE PROFILE_ID='$_REQUEST[profile_id]'"),array(),array('MODNAME'));
  99. unset($tmp_menu);
  100. unset($_REQUEST['modfunc']);
  101. unset($_REQUEST['can_edit']);
  102. unset($_REQUEST['can_use']);
  103. }
  104. if($_REQUEST['new_profile_title'] && AllowEdit())
  105. {
  106. $id = DBGet(DBQuery("SELECT ".db_seq_nextval('USER_PROFILES_SEQ')." AS ID".FROM_DUAL));
  107. $id = $id[1]['ID'];
  108. $exceptions_RET = array();
  109. DBQuery("INSERT INTO USER_PROFILES (ID,TITLE,PROFILE) values('$id','".$_REQUEST['new_profile_title']."','".$_REQUEST['new_profile_type']."')");
  110. $_REQUEST['profile_id'] = $id;
  111. $xprofile = $_REQUEST['new_profile_type'];
  112. unset($_REQUEST['new_profile_title']);
  113. unset($_REQUEST['new_profile_type']);
  114. unset($_SESSION['_REQUEST_vars']['new_profile_title']);
  115. unset($_SESSION['_REQUEST_vars']['new_profile_type']);
  116. }
  117. if($_REQUEST['modfunc']!='delete')
  118. {
  119. PopTable('header','Permissions');
  120. echo "<FORM name=pref_form id=pref_form action=Modules.php?modname=$_REQUEST[modname]&modfunc=update&profile_id=$_REQUEST[profile_id] method=POST>";
  121. DrawHeaderHome('Select the programs that users of this profile can use and which programs those users can use to save information.');
  122. echo '<BR>';
  123. echo '<TABLE width=100%><TR><TD valign=top width=26%>';
  124. echo '<TABLE border=0 cellpadding=0 cellspacing=0>';
  125. $style = ' style="border:1px; border-style: none none none none; padding:4px;"';
  126. $style1 = ' style="border:1px; border-style: solid none none none;"';
  127. //$profiles_RET = DBGet(DBQuery("SELECT ID,TITLE,PROFILE FROM USER_PROFILES"));
  128. $profiles_RET = DBGet(DBQuery("SELECT ID,TITLE,PROFILE FROM USER_PROFILES ORDER BY ID"),array(),array('PROFILE','ID'));
  129. echo '<TR><TD colspan=3 style="border:1px; border-style: none none solid none;"><b>Profiles</b></TD></TR>';
  130. foreach(array('admin','teacher','parent','student') as $profiles)
  131. {
  132. foreach($profiles_RET[$profiles] as $id=>$profile)
  133. {
  134. if($_REQUEST['profile_id']!='' && $id==$_REQUEST['profile_id'])
  135. echo '<TR id=selected_tr onmouseover="" onmouseout="" bgcolor="'.Preferences('HIGHLIGHT').'"; this.style.color="white";\'><TD width=20 align=right'.$style.'>'.(AllowEdit()&&$id>3?button('remove','',"Modules.php?modname=$_REQUEST[modname]&modfunc=delete&profile_id=$id",20):'').'</TD><TD '.$style.' onclick="document.location.href=\'Modules.php?modname='.$_REQUEST['modname'].'&profile_id='.$id.'\';">';
  136. else
  137. echo '<TR onmouseover=\'this.style.backgroundColor="'.Preferences('HIGHLIGHT').'"; this.style.color="white";\' onmouseout=\'this.style.cssText="background-color:transparent; color:black;";\'><TD width=20 align=right'.$style.'>'.(AllowEdit()&&$id>3?button('remove','',"Modules.php?modname=$_REQUEST[modname]&modfunc=delete&profile_id=$id",15):'').'</TD><TD'.$style.' onclick="document.location.href=\'Modules.php?modname='.$_REQUEST['modname'].'&profile_id='.$id.'\';">';
  138. echo '<b><a style="cursor: pointer; cursor:hand; text-decoration:none;">'.($id>3?'':'<b>').$profile[1]['TITLE'].($id>3?'':'</b>').'</a></b> &nbsp;';
  139. echo '</TD>';
  140. echo '<TD'.$style.'><A style="cursor: pointer;"><IMG SRC=assets/arrow_right.gif></A></TD>';
  141. echo '</TR>';
  142. }
  143. }
  144. if($_REQUEST['profile_id']=='')
  145. echo '<TR id=selected_tr><TD height=0></TD></TR>';
  146. if(AllowEdit())
  147. {
  148. echo '<TR id=new_tr><TD colspan=3'.$style1.'>';
  149. echo '<a style="cursor: pointer;" onclick=\'document.getElementById("selected_tr").onmouseover="this.style.backgroundColor=\"'.Preferences('HIGHLIGHT').'\"; this.style.color=\"white\";"; document.getElementById("selected_tr").onmouseout="this.style.cssText=\"background-color:transparent; color:black;\";"; document.getElementById("selected_tr").style.cssText="background-color:transparent; color:black;"; changeHTML({"new_id_div":"new_id_content"},["main_div"]);document.getElementById("new_tr").onmouseover="";document.getElementById("new_tr").onmouseout="";this.onclick="";\'><b> Add a User Profile<BR></a><br><DIV id=new_id_div></DIV> </b>';
  150. echo '</TD>';
  151. //echo '<TD'.$style.'><A style="cursor: pointer; cursor:hand;"><IMG SRC=assets/arrow_right.gif></A>&nbsp;</TD>';
  152. #echo "<td></td>";
  153. echo '</TR>';
  154. }
  155. echo '</TABLE>';
  156. echo '</TD><TD width=20 class=vbreak></TD><TD>';
  157. echo '<DIV id=main_div>';
  158. if($_REQUEST['profile_id']!='')
  159. {
  160. #PopTable('header','Permissions');
  161. echo '<TABLE border=0 cellspacing=0>';
  162. echo '<TR><TD colspan=5 style="border:1px; border-style: none none solid none;"><b>Permissions</b></TD></TR>';
  163. foreach($menuprof as $modcat=>$profiles)
  164. {
  165. $values = $profiles[$xprofile];
  166. echo '<TR><TD valign=top class=grid align=right style="white-space: nowrap; padding:6px 2px 2px 6px" >';
  167. echo "<b>".str_replace('_',' ',$modcat)."</b></TD><TD width=3 class=grid>&nbsp;</TD>";
  168. echo "<td class=grid style='white-space: nowrap; padding:2px 2px 2px 6px;'>Can Use".(AllowEdit()?"<INPUT type=checkbox name=can_use_$modcat onclick='checkAll(this.form,this.form.can_use_$modcat.checked,\"can_use[$modcat\");'>":'')."</td>";
  169. if($xprofile=='admin' || $modcat=='Students')
  170. echo"<td class=grid style='white-space: nowrap; padding:2px 2px 2px 6px;' > &nbsp;Can Edit".(AllowEdit()?"<INPUT type=checkbox name=can_edit_$modcat onclick='checkAll(this.form,this.form.can_edit_$modcat.checked,\"can_edit[$modcat\");'>":'')."</td>";
  171. else
  172. echo"<td class=grid></td>";
  173. echo "<td class=grid></td></TR>";
  174. if(count($values))
  175. {
  176. foreach($values as $file=>$title)
  177. {
  178. if(!is_numeric($file))
  179. {
  180. $can_use = $exceptions_RET[$file][1]['CAN_USE'];
  181. $can_edit = $exceptions_RET[$file][1]['CAN_EDIT'];
  182. echo "<TR><TD></TD><TD ></TD>";
  183. echo "<TD align=left style='padding:0px 0px 0px 47px'><INPUT type=checkbox name=can_use[".str_replace('.','_',$file)."] value=true".($can_use=='Y'?' CHECKED':'').(AllowEdit()?'':' DISABLED')."></TD>";
  184. if($xprofile=='admin')
  185. echo "<TD align=left style='padding:0px 0px 0px 47px'><INPUT type=checkbox name=can_edit[".str_replace('.','_',$file)."] value=true".($can_edit=='Y'?' CHECKED':'').(AllowEdit()?'':' DISABLED')."></TD>";
  186. else
  187. echo "<TD align=center></TD>";
  188. echo "<TD > &nbsp; &nbsp;$title</TD></TR><TR><TD></TD><TD></TD><TD colspan=3 class=break></TR>";
  189. if($modcat=='Students' && $file=='Students/Student.php')
  190. {
  191. $categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STUDENT_FIELD_CATEGORIES ORDER BY SORT_ORDER,TITLE"));
  192. foreach($categories_RET as $category)
  193. {
  194. $file = 'Students/Student.php&category_id='.$category['ID'];
  195. $title = ' &nbsp; &nbsp; &rsaquo; '.$category['TITLE'];
  196. $can_use = $exceptions_RET[$file][1]['CAN_USE'];
  197. $can_edit = $exceptions_RET[$file][1]['CAN_EDIT'];
  198. echo "<TR><TD></TD><TD></TD>";
  199. echo "<TD align=left style='padding:0px 0px 0px 47px'><INPUT type=checkbox name=can_use[".str_replace('.','_',$file)."] value=true".($can_use=='Y'?' CHECKED':'').(AllowEdit()?'':' DISABLED')."></TD>";
  200. echo "<TD align=left style='padding:0px 0px 0px 47px'><INPUT type=checkbox name=can_edit[".str_replace('.','_',$file)."] value=true".($can_edit=='Y'?' CHECKED':'').(AllowEdit()?'':' DISABLED')."></TD>";
  201. echo "<TD >$title</TD></TR><TR><TD></TD><TD></TD><TD colspan=3 class=break_headers></TR>";
  202. }
  203. }
  204. elseif($modcat=='Users' && $file=='Users/User.php')
  205. {
  206. $categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STAFF_FIELD_CATEGORIES ORDER BY SORT_ORDER,TITLE"));
  207. foreach($categories_RET as $category)
  208. {
  209. $file = 'Users/User.php&category_id='.$category['ID'];
  210. $title = ' &nbsp; &nbsp; &rsaquo; '.$category['TITLE'];
  211. $can_use = $exceptions_RET[$file][1]['CAN_USE'];
  212. $can_edit = $exceptions_RET[$file][1]['CAN_EDIT'];
  213. echo "<TR><TD></TD><TD></TD>";
  214. echo "<TD align=left style='padding:0px 0px 0px 47px'><INPUT type=checkbox name=can_use[".str_replace('.','_',$file)."] value=true".($can_use=='Y'?' CHECKED':'').(AllowEdit()?'':' DISABLED')."></TD>";
  215. echo "<TD align=left style='padding:0px 0px 0px 47px'><INPUT type=checkbox name=can_edit[".str_replace('.','_',$file)."] value=true".($can_edit=='Y'?' CHECKED':'').(AllowEdit()?'':' DISABLED')."></TD>";
  216. echo "<TD style='white-space: nowrap;'> &nbsp; &nbsp;$title</TD></TR><TR><TD></TD><TD></TD><TD colspan=3 class=break_headers></TR>";
  217. }
  218. }
  219. }
  220. else
  221. echo '<TR><TD></TD><TD></TD><TD colspan=3 style=background-color:#bee6f2 align=right><b> '.$title.' </b></TD></TR>';
  222. }
  223. }
  224. echo '<TR><TD colspan=5 align=center height=20></TD></TR>';
  225. }
  226. echo '</TABLE>';
  227. #PopTable('footer');
  228. // echo '<CENTER>'.SubmitButton('Save', '', 'class=btn_medium onclick=\'formload_ajax("pref_form");\'').'</CENTER>';
  229. echo '<CENTER>'.SubmitButton('Save', '', 'class=btn_medium').'</CENTER>';
  230. // pref_form
  231. }
  232. echo '</DIV>';
  233. echo '</TD></TR></TABLE>';
  234. echo '</FORM>';
  235. PopTable('footer');
  236. echo '<DIV id=new_id_content style="position:absolute;visibility:hidden;"><fieldset><legend>Add a User Profile</legend><table><tr><td width=30>Title </td><td><INPUT type=text name=new_profile_title></td></tr>';
  237. echo '<tr><td width=30>Type </td><td><SELECT name=new_profile_type><OPTION value=admin>Administrator<OPTION value=teacher>Teacher<OPTION value=parent>Parent</SELECT>
  238. <br></td></tr><tr><td colspan=2 align=center><input type=submit value=save class=btn_medium></td></tr></table></fieldset></DIV>';
  239. }
  240. ?>