m_item_origineel.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. Item-manager (add, edit & delete)
  5. */
  6. require_once('rsys.php');
  7. Rsys :: protect_script('m_item');
  8. $tool_name = get_lang('ItemManagerHeader');
  9. //$interbreadcrumb[] = array ("url" => "../admin/index.php", "name" => get_lang('PlatformAdmin'));
  10. /**
  11. * Filter to display the modify-buttons
  12. *
  13. * @param - int $id The item-id
  14. */
  15. function modify_filter($id) {
  16. $str='';
  17. $outtt=false;
  18. if(Rsys::item_allow($id,'edit')){
  19. $str.='<a href="m_item.php?action=edit&amp;id='.$id.'" title="'.get_lang("EditItem2").'"><img alt="" src="../img/edit.gif" /></a>';
  20. }
  21. if(Rsys::item_allow($id,'m_rights')) $str.=' &nbsp;<a href="m_item.php?action=m_rights&amp;item_id='.$id.'" title="'.get_lang("MRights").'"><img alt="" src="../img/info_small.gif" /></a>';
  22. if(Rsys::item_allow($id,'delete')) $str.=' <a href="m_item.php?action=delete&amp;id='.$id.'" title="'.get_lang("DeleteItem").'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmDeleteItem")))."'".')) return false;"><img alt="" src="../img/delete.gif" /></a>';
  23. if(Rsys::item_allow($id,'edit')){
  24. $number = Rsys :: get_item($id);
  25. $str.= ' <a href="m_item.php?action=blackout&amp;id='.$id.'" title="'.get_lang("Blackout").'"><img alt="" src="../img/blackout'.$number[5].'.gif" /></a>';
  26. }
  27. return $str;
  28. }
  29. /**
  30. * Filter to display the modify-buttons
  31. *
  32. * @param - int $id The item-rights-id's
  33. */
  34. function modify_rights_filter($id) {
  35. return ' <a href="m_item.php?action=m_rights&amp;subaction=delete&amp;item_id='.substr($id, 0, strpos($id, '-')).'&amp;class_id='.substr($id, strrpos($id, '-') + 1).'" title="'.get_lang("RemoveClassRights").'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmDeleteItem"), ENT_QUOTES, api_get_system_encoding()))."'".')) return false;"><img alt="" src="../img/delete.gif" /></a>';
  36. }
  37. if (isset ($_POST['action'])) {
  38. switch ($_POST['action']) {
  39. case 'delete_items' :
  40. $ids = $_POST['items'];
  41. $warning = false;
  42. if (count($ids) > 0) {
  43. foreach ($ids as $id) {
  44. $result = Rsys :: delete_item($id);
  45. if ($result != 0 && $warning <> true) // TODO: A strange looking logical condition, to be cleaned.
  46. $warning = true;
  47. }
  48. ob_start();
  49. if ($warning) {
  50. Display :: display_normal_message(get_lang('ItemNotDeleted'), false);
  51. } else {
  52. Display :: display_normal_message(get_lang('ItemDeleted'),false);
  53. }
  54. $msg = ob_get_contents();
  55. ob_end_clean();
  56. }
  57. break;
  58. case 'delete_itemrights' :
  59. $ids = $_POST['itemrights'];
  60. if (count($ids) > 0) {
  61. foreach ($ids as $id)
  62. Rsys :: delete_item_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1));
  63. ob_start();
  64. Display :: display_normal_message(get_lang('ItemRightDeleted'),false);
  65. $msg = ob_get_contents();
  66. ob_end_clean();
  67. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  68. } else {
  69. header("Location: ".$_SERVER['HTTP_REFERER']);
  70. exit ();
  71. }
  72. $_GET['action'] = 'm_rights';
  73. break;
  74. case 'set_r_rights' :
  75. $ids = $_POST['itemrights'];
  76. if (count($ids) > 0) {
  77. foreach ($ids as $id)
  78. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'view_right', 1);
  79. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  80. } else {
  81. header("Location: ".$_SERVER['HTTP_REFERER']);
  82. exit ();
  83. }
  84. $_GET['action'] = 'm_rights';
  85. break;
  86. case 'unset_r_rights' :
  87. $ids = $_POST['itemrights'];
  88. if (count($ids) > 0) {
  89. foreach ($ids as $id)
  90. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'view_right', 0);
  91. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  92. } else {
  93. header("Location: ".$_SERVER['HTTP_REFERER']);
  94. exit ();
  95. }
  96. $_GET['action'] = 'm_rights';
  97. break;
  98. case 'set_edit_rights' :
  99. $ids = $_POST['itemrights'];
  100. if (count($ids) > 0) {
  101. foreach ($ids as $id)
  102. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'edit_right', 1);
  103. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  104. } else {
  105. header("Location: ".$_SERVER['HTTP_REFERER']);
  106. exit ();
  107. }
  108. $_GET['action'] = 'm_rights';
  109. break;
  110. case 'unset_edit_rights' :
  111. $ids = $_POST['itemrights'];
  112. if (count($ids) > 0) {
  113. foreach ($ids as $id)
  114. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'edit_right', 0);
  115. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  116. } else {
  117. header("Location: ".$_SERVER['HTTP_REFERER']);
  118. exit ();
  119. }
  120. $_GET['action'] = 'm_rights';
  121. break;
  122. case 'set_delete_rights' :
  123. $ids = $_POST['itemrights'];
  124. if (count($ids) > 0) {
  125. foreach ($ids as $id)
  126. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'delete_right', 1);
  127. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  128. } else {
  129. header("Location: ".$_SERVER['HTTP_REFERER']);
  130. exit ();
  131. }
  132. $_GET['action'] = 'm_rights';
  133. break;
  134. case 'unset_delete_rights' :
  135. $ids = $_POST['itemrights'];
  136. if (count($ids) > 0) {
  137. foreach ($ids as $id)
  138. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'delete_right', 0);
  139. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  140. } else {
  141. header("Location: ".$_SERVER['HTTP_REFERER']);
  142. exit ();
  143. }
  144. $_GET['action'] = 'm_rights';
  145. break;
  146. case 'set_mres_rights' :
  147. $ids = $_POST['itemrights'];
  148. if (count($ids) > 0) {
  149. foreach ($ids as $id)
  150. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'm_reservation', 1);
  151. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  152. } else {
  153. header("Location: ".$_SERVER['HTTP_REFERER']);
  154. exit ();
  155. }
  156. $_GET['action'] = 'm_rights';
  157. break;
  158. case 'unset_mres_rights' :
  159. $ids = $_POST['itemrights'];
  160. if (count($ids) > 0) {
  161. foreach ($ids as $id)
  162. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'm_reservation', 0);
  163. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  164. } else {
  165. header("Location: ".$_SERVER['HTTP_REFERER']);
  166. exit ();
  167. }
  168. $_GET['action'] = 'm_rights';
  169. break;
  170. case 'set_all_rights' :
  171. $ids = $_POST['itemrights'];
  172. if (count($ids) > 0) {
  173. foreach ($ids as $id){
  174. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'm_reservation', 1);
  175. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'edit_right', 1);
  176. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'delete_right', 1);
  177. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'view_right', 1);
  178. }
  179. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  180. } else {
  181. header("Location: ".$_SERVER['HTTP_REFERER']);
  182. exit ();
  183. }
  184. $_GET['action'] = 'm_rights';
  185. break;
  186. case 'unset_all_rights' :
  187. $ids = $_POST['itemrights'];
  188. if (count($ids) > 0) {
  189. foreach ($ids as $id){
  190. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'm_reservation', 0);
  191. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'edit_right', 0);
  192. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'delete_right', 0);
  193. Rsys :: set_new_right(substr($id, 0, strpos($id, '-')), substr($id, strrpos($id, '-') + 1), 'view_right', 0);
  194. }
  195. $_GET['item_id'] = substr($id, 0, strpos($id, '-'));
  196. } else {
  197. header("Location: ".$_SERVER['HTTP_REFERER']);
  198. exit ();
  199. }
  200. $_GET['action'] = 'm_rights';
  201. break;
  202. }
  203. }
  204. switch ($_GET['action']) {
  205. case 'm_rights' :
  206. if(!Rsys::item_allow($_GET['item_id'],'m_rights')) die('No Access!');
  207. switch ($_GET['subaction']) {
  208. case 'edit' :
  209. $item = Rsys :: get_item($_GET['item_id']);
  210. $classDB = Rsys :: get_class_group($_GET['class_id']);
  211. $item_rights = Rsys :: get_item_rights($_GET['item_id'], $_GET['class_id']);
  212. $interbreadcrumb[] = array ("url" => "m_item.php", "name" => $tool_name);
  213. $interbreadcrumb[] = array ("url" => "m_item.php?&action=m_rights&id=".$item['id'], "name" => str_replace('#ITEM#', $item['name'], get_lang('MItemRights')));
  214. Display :: display_header(get_lang('EditRight'));
  215. api_display_tool_title(get_lang('EditRight'));
  216. $form = new FormValidator('itemright', 'post', "m_item.php?id=".$item['id']."&action=m_rights&subaction=edit");
  217. $form->add_textfield('classn', get_lang('LangClass'), true, array ('readonly' => 'readonly'));
  218. $form->addElement('checkbox', 'edit_right', get_lang('EditRight'));
  219. $form->addElement('checkbox', 'delete_right', get_lang('DeleteRight'));
  220. $form->addElement('checkbox', 'm_reservation', get_lang('MReservationRight'));
  221. $form->addElement('hidden', 'item_id', $item['id']);
  222. $form->addElement('hidden', 'class_id', $_GET['class_id']);
  223. $item_right['classn'] = $classDB[0]['name'];
  224. $item_right['edit_right'] = $item_rights[0]['edit_right'];
  225. $item_right['delete_right'] = $item_rights[0]['delete_right'];
  226. $item_right['m_reservation'] = $item_rights[0]['m_reservation'];
  227. $form->setDefaults($item_right);
  228. $form->addElement('submit', 'submit', get_lang('Ok'));
  229. if ($form->validate()) {
  230. $values = $form->exportValues();
  231. Rsys :: edit_item_right($values['item_id'], $values['class_id'], $values['edit_right'], $values['delete_right'], $values['m_reservation']);
  232. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ItemRightEdited'), "m_item.php?id=".$_GET['id']."&action=m_rights", str_replace('#ITEM#', $item['name'], get_lang('MItemRights'))),false);
  233. } else
  234. $form->display();
  235. break;
  236. case 'delete' :
  237. Rsys :: delete_item_right($_GET['item_id'], $_GET['class_id']);
  238. ob_start();
  239. Display :: display_normal_message(get_lang('ItemRightDeleted'),false);
  240. $msg = ob_get_contents();
  241. ob_end_clean();
  242. case 'switch' :
  243. switch ($_GET['switch']) {
  244. case 'edit' :
  245. Rsys :: set_new_right($_GET['item_id'], $_GET['class_id'], 'edit_right', $_GET['set']);
  246. break;
  247. case 'delete' :
  248. Rsys :: set_new_right($_GET['item_id'], $_GET['class_id'], 'delete_right', $_GET['set']);
  249. break;
  250. case 'manage' :
  251. Rsys :: set_new_right($_GET['item_id'], $_GET['class_id'], 'm_reservation', $_GET['set']);
  252. break;
  253. case 'view' :
  254. Rsys :: set_new_right($_GET['item_id'], $_GET['class_id'], 'view_right', $_GET['set']);
  255. break;
  256. }
  257. default :
  258. $item = Rsys :: get_item($_GET['item_id']);
  259. $NoSearchResults = get_lang('NoRights');
  260. $interbreadcrumb[] = array ("url" => "m_item.php", "name" => $tool_name);
  261. Display :: display_header(str_replace('#ITEM#', $item['name'], get_lang('MItemRights')));
  262. api_display_tool_title(get_lang('MItemRights2'));
  263. echo $msg;
  264. $table = new SortableTable('itemrights', array ('Rsys', 'get_num_itemrights'), array ('Rsys', 'get_table_itemrights'), 1);
  265. $table->set_header(0, '', false, array ('style' => 'width:10px'));
  266. $table->set_additional_parameters(array('action'=>'m_rights','item_id'=>$_GET['item_id']));
  267. $table->set_header(1, get_lang('LangClass'), false);
  268. $table->set_header(2, get_lang('EditItemRight'), false);
  269. $table->set_header(3, get_lang('DeleteItemRight'), false);
  270. $table->set_header(4, get_lang('MReservationPeriodsRight'), false);
  271. $table->set_header(5, get_lang('ViewItemRight'), false);
  272. $table->set_header(6, '', false, array ('style' => 'width:50px;'));
  273. $table->set_column_filter(6, 'modify_rights_filter');
  274. $table->set_form_actions(array (
  275. 'delete_itemrights' => get_lang('DeleteSelectedItemRights'),
  276. 'set_edit_rights' => get_lang('SetEditRights'),
  277. 'unset_edit_rights' => get_lang('UnsetEditRights'),
  278. 'set_delete_rights' => get_lang('SetDeleteRights'),
  279. 'unset_delete_rights' => get_lang('UnsetDeleteRights'),
  280. 'set_mres_rights' => get_lang('SetMresRights'),
  281. 'unset_mres_rights' => get_lang('UnsetMresRights'),
  282. 'set_r_rights' => get_lang('SetViewRights'),
  283. 'unset_r_rights' => get_lang('UnsetViewRights'),
  284. 'set_all_rights' => get_lang('SetAllRights'),
  285. 'unset_all_rights' => get_lang('UnsetAllRights')
  286. ), 'itemrights');
  287. $table->display();
  288. }
  289. break;
  290. case 'add' :
  291. $interbreadcrumb[] = array ("url" => "m_item.php", "name" => $tool_name);
  292. Display :: display_header(get_lang('AddNewItem'));
  293. api_display_tool_title(get_lang('AddNewItem'));
  294. $form = new FormValidator('item', 'post', 'm_item.php?action=add');
  295. $cats = Rsys :: get_category();
  296. foreach ($cats as $cat)
  297. $catOptions[$cat['id']] = $cat['name'];
  298. $form->addElement('select', 'category', get_lang('Category'), $catOptions);
  299. $form->add_textfield('name', get_lang('ItemName'), true, array ('maxlength' => '128'));
  300. $form->addElement('textarea', 'description', get_lang('ItemDescription'), array ('rows' => '3', 'cols' => '40'));
  301. $form->addRule('category', get_lang('ThisFieldIsRequired'), 'required');
  302. // TODO: get list of courses (to link it to the item)
  303. //$form->addElement('select', 'course_code', get_lang('ItemCourse'),array(''=>'','value'=>'tag'));
  304. //$form->addRule('course', get_lang('ThisFieldIsRequired'), 'required');
  305. $form->addElement('submit', 'submit', get_lang('Ok'));
  306. if ($form->validate()) {
  307. $values = $form->exportValues();
  308. if (Rsys :: add_item($values['name'], $values['description'], $values['category'], $values['course_code']))
  309. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ItemAdded'), "m_item.php", $tool_name),false);
  310. else
  311. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ItemExist'), "m_item.php?action=add", get_lang('AddNewItem')),false);
  312. } else
  313. $form->display();
  314. break;
  315. case 'edit' :
  316. $item = Rsys :: get_item($_GET['id']);
  317. $cats = Rsys :: get_category();
  318. foreach ($cats as $cat)
  319. $catOptions[$cat['id']] = $cat['name'];
  320. $interbreadcrumb[] = array ("url" => "m_item.php", "name" => $tool_name);
  321. Display :: display_header(str_replace('#ITEM#', $item['name'], get_lang('EditItem')));
  322. api_display_tool_title(get_lang('EditItem2'));
  323. $form = new FormValidator('item', 'post', 'm_item.php?action=edit');
  324. $form->addElement('select', 'category_id', get_lang('Category'), $catOptions);
  325. $form->add_textfield('name', get_lang('ItemName'), array ('maxlength' => '128'));
  326. $form->addElement('textarea', 'description', get_lang('ItemDescription'), array ('rows' => '3', 'cols' => '40'));
  327. $form->addRule('category_id', get_lang('ThisFieldIsRequired'), 'required');
  328. $form->addElement('hidden', 'id', $item['id']);
  329. $form->addElement('submit', 'submit', get_lang('Ok'));
  330. $form->setDefaults($item);
  331. if ($form->validate()) {
  332. $values = $form->exportValues();
  333. if (Rsys :: edit_item($values['id'], $values['name'], $values['description'], $values['category_id'], $values['course_id']))
  334. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ItemEdited'), "m_item.php", $tool_name),false);
  335. else
  336. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ItemExist'), "m_item.php?action=edit&id=".$values['id'], get_lang('EditItem2')),false);
  337. } else
  338. $form->display();
  339. break;
  340. case 'delete' :
  341. $result = Rsys :: delete_item($_GET['id']);
  342. ob_start();
  343. if($result == '0'){
  344. Display :: display_normal_message(get_lang('ItemDeleted'),false);}
  345. else
  346. Display :: display_normal_message(str_replace('#NUM#', $result, get_lang('ItemHasReservations')),false);
  347. $msg = ob_get_contents();
  348. ob_end_clean();
  349. default :
  350. $NoSearchResults = get_lang('NoItem');
  351. Display :: display_header($tool_name);
  352. api_display_tool_title($tool_name);
  353. echo $msg;
  354. if($_GET['action'] == 'blackout'){
  355. $result = Rsys :: black_out_changer($_GET['id']);
  356. Display :: display_normal_message(get_lang('BlackoutPage'.$result),false);
  357. }
  358. echo '<form id="cat_form" action="m_item.php" method="get"><div style="float: left;"><a href="m_item.php?action=add">'.get_lang('AddNewItem').'</a></div><div style="text-align: right;">'.get_lang('CategoryFilter').': <select name="cat" onchange="this.form.submit();"><option value="0">*** '.get_lang('All').' ***</option>';
  359. $cats = Rsys :: get_category_with_items_manager();
  360. foreach ($cats as $cat)
  361. echo '<option value="'.$cat['id'].'"'. ($cat['id'] == $_GET['cat'] ? ' selected="selected"' : '').'>'.$cat['name'].'</option>';
  362. echo '</select></div></form>';
  363. echo "hier";
  364. $table = new SortableTable('item', array ('Rsys', 'get_num_items'), array ('Rsys', 'get_table_items'), 1);
  365. echo "hier2";
  366. $table->set_additional_parameters(array('cat'=>$_GET['cat']));
  367. $table->set_header(0, '', false, array ('style' => 'width:10px'));
  368. $table->set_header(1, get_lang('ItemName'), true);
  369. $table->set_header(2, get_lang('ItemDescription'), true);
  370. $table->set_header(3, get_lang('Category'), true);
  371. $table->set_header(4, get_lang('ItemCreator'), true);
  372. $table->set_header(5, '', false, array ('style' => 'width:100px;'));
  373. $table->set_column_filter(5, 'modify_filter');
  374. $table->set_form_actions(array ('delete_items' => get_lang('DeleteSelectedItems')), 'items');
  375. $table->display();
  376. }
  377. /**
  378. ---------------------------------------------------------------------
  379. */
  380. Display :: display_footer();
  381. ?>