danogwok

codeigniter error

Feb 3rd, 2014
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. the Controller
  2.  
  3. <?php
  4.  
  5. #**************************************************************************************
  6. # All Inventory actions go through this controller
  7. #**************************************************************************************
  8.  
  9. class Library extends Controller {
  10. # Constructor
  11. function Library()
  12. {
  13. parent::Controller();
  14.  
  15. date_default_timezone_set(SYS_TIMEZONE);
  16. $this->load->library('excelexport','excelexport');
  17. }
  18. var $schoolinfo ;
  19.  
  20. # Default to nothing
  21. function index()
  22. {
  23. #Do nothing
  24. }
  25.  
  26. # save Stock data
  27. function load_stock_form()
  28. {
  29. access_control($this);
  30. $schooldetails = $this->session->userdata('schoolinfo');
  31. # Get the passed details into the url data array if any
  32. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  33.  
  34. # Pick all assigned data
  35. $data = assign_to_data($urldata);
  36.  
  37. #Get the Item details
  38. if(!empty($data['i']))
  39. {
  40. $editid = decryptValue($data['i']);
  41. $data['formdata'] = $this->Query_reader->get_row_as_array('get_stock_by_id', array('id'=>$editid) );
  42. }
  43.  
  44.  
  45.  
  46.  
  47. if($this->input->post('savestock')){
  48.  
  49. $required_fields = array('stocktitle', 'sectionid', 'author', 'stocknumber');
  50. $_POST = clean_form_data($_POST);
  51. $validation_results = validate_form('', $_POST, $required_fields);
  52.  
  53. if($validation_results['bool'])
  54. {
  55. if(!empty($data['formdata']) && !empty($data['i']))
  56. {
  57. $save_result = $this->db->query($this->Query_reader->get_query_by_code('update_stock', array_merge($_POST, array('id'=>$editid)) ));
  58. }
  59. else
  60. {
  61. $save_result = $this->db->query($this->Query_reader->get_query_by_code('add_stock', array_merge($_POST, array('school' => $schooldetails['id'], 'createdby'=>$this->session->userdata('userid'))) ));
  62. }
  63.  
  64. if($save_result)
  65. {
  66. $data['msg'] = "The stock has been saved.";
  67. #die($data['msg']);
  68. $this->session->set_userdata('sres', $data['msg']);
  69.  
  70. redirect(base_url()."library/manage_stock/m/sres");
  71. }
  72. else
  73. {
  74. $data['msg'] = "ERROR: The stock was not saved. Please contact your administrator.";
  75. #die($data['msg']);
  76. }
  77. } #Validation
  78.  
  79. if((empty($validation_results['bool']) || (!empty($validation_results['bool']) && !$validation_results['bool']))
  80. && empty($data['msg']) )
  81. {
  82. $data['msg'] = "WARNING: The highlighted fields are required.";
  83.  
  84. }
  85.  
  86. $data['requiredfields'] = $validation_results['requiredfields'];
  87. $data['formdata'] = $_POST;
  88. }
  89. #Check if the user is simply viewing the deal
  90. #TODO: Add the force-users-without-other-permissions-to-view condition
  91. if(!empty($data['a']) && decryptValue($data['a']) == 'view')
  92. {
  93. $data['stockdata'] = $data['formdata'];
  94. $data['isviewing'] = TRUE;
  95. $data['area'] = 'stock_details';
  96. $this->load->view('incl/addons', $data);
  97. }
  98. else
  99. $this->load->view('library/new_stock_view',$data);
  100. }
  101.  
  102. # save Stock Item data
  103. function load_stock_item_form()
  104. {
  105. access_control($this);
  106. $schooldetails = $this->session->userdata('schoolinfo');
  107. # Get the passed details into the url data array if any
  108. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  109.  
  110. # Pick all assigned data
  111. $data = assign_to_data($urldata);
  112.  
  113.  
  114. #Get the Item details
  115. if(!empty($data['i']))
  116. {
  117. $editid = decryptValue($data['i']);
  118. $data['formdata'] = $this->Query_reader->get_row_as_array('get_stock_item_by_id', array('id'=>$editid) );
  119. }
  120.  
  121. #Get the Item details
  122. if(!empty($data['s']))
  123. {
  124. $stockid = decryptValue($data['s']);
  125. #$stockid = $data['s'];
  126. $data['stockdata'] = $this->Query_reader->get_row_as_array('get_stock_by_id', array('id'=>$stockid) );
  127.  
  128. }
  129.  
  130. if($this->input->post('savestockitem')){
  131.  
  132. $required_fields = array('stockid','createdon','serialnumber');
  133. $_POST = clean_form_data($_POST);
  134. $validation_results = validate_form('', $_POST, $required_fields);
  135. if($validation_results['bool'])
  136. {
  137. if(!empty($data['formdata']) && !empty($data['i']))
  138. {
  139. $save_result = $this->db->query($this->Query_reader->get_query_by_code('update_stock_item', array_merge($_POST, array('id'=>$editid)) ));
  140. }
  141. else
  142. {
  143. #die($this->Query_reader->get_query_by_code('add_stock_item', array_merge($_POST, array('createdby'=>$this->session->userdata('userid'))) ));
  144. $save_result = $this->db->query($this->Query_reader->get_query_by_code('add_stock_item', array_merge($_POST, array('createdby'=>$this->session->userdata('userid'))) ));
  145. }
  146.  
  147. if($save_result)
  148. {
  149. $data['msg'] = "The stock item has been saved.";
  150. #die($data['msg']);
  151. $this->session->set_userdata('sres', $data['msg']);
  152.  
  153. redirect(base_url()."library/manage_stock/m/sres");
  154. }
  155. else
  156. {
  157. $data['msg'] = "ERROR: The stock item was not saved. Please contact your administrator.";
  158. #die($data['msg']);
  159. }
  160. } #Validation
  161.  
  162. if((empty($validation_results['bool']) || (!empty($validation_results['bool']) && !$validation_results['bool']))
  163. && empty($data['msg']) )
  164. {
  165. $data['msg'] = "WARNING: The highlighted fields are required.";
  166. }
  167.  
  168. $data['requiredfields'] = $validation_results['requiredfields'];
  169. $data['formdata'] = $_POST;
  170. }
  171. #Check if the user is simply viewing the item
  172. #TODO: Add the force-users-without-other-permissions-to-view condition
  173. if(!empty($data['a']) && decryptValue($data['a']) == 'view')
  174. {
  175. // $data['stockdata'] = $data['formdata'];
  176. $data['itemdata'] = $data['formdata'];
  177. $data['isviewing'] = TRUE;
  178. $data['area'] = 'stock_item_details';
  179. $this->load->view('incl/addons', $data);
  180. }
  181. else
  182. $this->load->view('library/new_stock_item_view',$data);
  183. }
  184.  
  185. # save borrower data
  186. function load_borrower_form()
  187. {
  188. access_control($this);
  189. $schooldetails = $this->session->userdata('schoolinfo');
  190.  
  191. # Get the passed details into the url data array if any
  192. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  193.  
  194. # Pick all assigned data
  195. $data = assign_to_data($urldata);
  196.  
  197. // var_dump($data);
  198. #####comment out.. use model values
  199. #Get the Item details
  200. $stockid = decryptValue($data['s']);
  201. #$stockid = $data['s'];
  202. $data['stockdata'] = $this->Query_reader->get_row_as_array('get_stock_by_id', array('id'=>$stockid) );
  203. echo "<pre>";
  204. print_r($data);
  205. echo "</pre>";
  206. #Get the Item details
  207. if(!empty($data['i']))
  208. {
  209. $editid = decryptValue($data['i']);
  210. $data['formdata'] = $this->Query_reader->get_row_as_array('get_borrower_by_id', array('id'=>$editid) );
  211. $data['formdata']['search'] = $data['formdata']['firstname']." ".$data['formdata']['middlename']." ".$data['formdata']['lastname'];
  212. }
  213.  
  214.  
  215. #Check if the user is simply viewing the deal
  216. #TODO: Add the force-users-without-other-permissions-to-view condition
  217. if(!empty($data['a']) && decryptValue($data['a']) == 'view')
  218. {
  219. $data['isview'] = "Y";
  220. }
  221.  
  222.  
  223. if($this->input->post('saveborrower')){
  224.  
  225. $required_fields = array('returndate','stockid','studentid','datetaken','items*COMBOBOX');
  226. $_POST = clean_form_data($_POST);
  227. $validation_results = validate_form('', $_POST, $required_fields);
  228. $borrowerperiod = validate_borrower_period($_POST['datetaken'],$_POST['returndate']);
  229. if($validation_results['bool'] && $borrowerperiod == "")
  230. {
  231.  
  232.  
  233. $_POST['copiestaken'] = sizeof($_POST['items']);
  234. if(!empty($data['formdata']) && !empty($data['i']))
  235. {
  236. $save_result = $this->db->query($this->Query_reader->get_query_by_code('update_borrower', array_merge($_POST, array('id'=>$editid)) ));
  237. }
  238. else
  239. {
  240. $save_result = $this->db->query($this->Query_reader->get_query_by_code('add_borrower', array_merge($_POST, array('school' => $schooldetails['id'], 'createdby'=>$this->session->userdata('userid'))) ));
  241. }
  242.  
  243. if($save_result)
  244. {
  245. $borrowerid = $this->db->insert_id();
  246. for($i=0; $i<sizeof($_POST['items']); $i++){
  247. $save_result2 = $this->db->query($this->Query_reader->get_query_by_code('add_borroweditems',array('borrower'=> $borrowerid,'item' => $_POST['items'][$i])));
  248. $updateitem = $this->db->query($this->Query_reader->get_query_by_code('update_item_borrowed',array('id' => $_POST['items'][$i], 'isavailable' => 0)));
  249. }
  250. if($save_result2 && $updateitem){
  251. $data['msg'] = "The borrower has been saved.";
  252. #die($data['msg']);
  253. $this->session->set_userdata('sres', $data['msg']);
  254.  
  255. redirect(base_url()."library/manage_borrowers/m/sres");
  256. }
  257. else
  258. $data['msg'] = "ERROR: The borrower was not saved. Please contact your administrator.";
  259. }
  260. else
  261. {
  262. $data['msg'] = "ERROR: The borrower was not saved. Please contact your administrator.";
  263. #die($data['msg']);
  264. }
  265.  
  266. } #Validation
  267.  
  268. if((empty($validation_results['bool']) || (!empty($validation_results['bool']) && !$validation_results['bool']))
  269. && empty($data['msg']) )
  270. {
  271. $data['msg'] = "WARNING: The highlighted fields are required.";
  272. }
  273.  
  274. if($borrowerperiod != "")
  275. $data['msg'] = "WARNING: ".$borrowerperiod;
  276. $data['requiredfields'] = $validation_results['requiredfields'];
  277. $data['formdata'] = $_POST;
  278. }
  279.  
  280. if(!empty($data['a']) && decryptValue($data['a']) == 'view')
  281. {
  282. $data = paginate_list($this, $data, 'get_borrowed_items', array('isactive'=>'Y', 'searchstring'=>' AND b.borrower = '.$data['formdata']['id']));
  283. $data['isviewing'] = TRUE;
  284. $data['area'] = 'borrower_details';
  285. $this->load->view('incl/addons', $data);
  286. }
  287. else
  288. echo "<pre>";
  289. print_r($data);
  290. echo "</pre>";
  291. $this->load->view('library/new_borrower_view',$data);
  292. }
  293.  
  294. # save Return data
  295. function return_rental()
  296. {
  297. access_control($this);
  298. $schooldetails = $this->session->userdata('schoolinfo');
  299. # Get the passed details into the url data array if any
  300. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  301.  
  302. # Pick all assigned data
  303. $data = assign_to_data($urldata);
  304. if(!empty($data['i']))
  305. {
  306. $data['rentaldata'] = $this->Query_reader->get_row_as_array('get_rental_data', array('id'=> decryptValue($data['i'])));
  307. }
  308.  
  309. if($this->input->post('returnrental'))
  310. {
  311. $required_fields = array('returndate','item*COMBOBOX');
  312. $_POST = clean_form_data($_POST);
  313. $validation_results = validate_form('', $_POST, $required_fields);
  314. if($validation_results['bool']){
  315. foreach($_POST['item'] as $item){
  316. if(!empty($item) && $item != ""){
  317. #echo $this->Query_reader->get_query_by_code('update_library',array_merge(array('item' => $item)));
  318. $save_result = $this->db->query($this->Query_reader->get_query_by_code('update_library',array('item' => $item, 'isavailable' => '1')));
  319. #echo $this->Query_reader->get_query_by_code('save_return',array_merge($_POST,array('item' => $item)));
  320. $save_result = $this->db->query($this->Query_reader->get_query_by_code('save_return',array_merge($_POST,array('item' => $item))));
  321. }
  322. }
  323. if($save_result)
  324. {
  325. $data['msg'] = "The return has been saved.";
  326. #die($data['msg']);
  327. $this->session->set_userdata('sres', $data['msg']);
  328. }
  329. else
  330. {
  331. $data['msg'] = "ERROR: The return was not saved. Please contact your administrator.";
  332. $this->session->set_userdata('sres', $data['msg']);
  333. }
  334. redirect(base_url()."library/manage_borrowers/m/sres");
  335. }
  336. if((empty($validation_results['bool']) || (!empty($validation_results['bool']) && !$validation_results['bool']))
  337. && empty($data['msg']) )
  338. {
  339. $data['msg'] = "WARNING: The highlighted fields are required.";
  340. }
  341.  
  342. $data['requiredfields'] = $validation_results['requiredfields'];
  343. $data['formdata'] = $_POST;
  344. }
  345. /*else
  346. {
  347. $data['msg'] = "ERROR: The return was not saved. Please contact your administrator.";
  348. #die($data['msg']);
  349. $this->session->set_userdata('sres', $data['msg']);
  350.  
  351. } */
  352.  
  353.  
  354. $this->load->view('library/return_rental_view', $data);
  355. }
  356.  
  357. function manage_stock(){
  358. access_control($this);
  359. $schooldetails = $this->session->userdata('schoolinfo');
  360.  
  361. # Get the passed details into the url data array if any
  362. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  363. # Pick all assigned data
  364. $data = assign_to_data($urldata);
  365.  
  366. #Get the paginated list of the deals
  367. $data = paginate_list($this, $data, 'get_stock_list', array('isactive'=>'Y', 'searchstring'=>' school = '.$schooldetails['id']));
  368.  
  369. $data = add_msg_if_any($this, $data);
  370. $this->load->view('library/manage_stock_view', $data);
  371. }
  372.  
  373. function manage_stock_items(){
  374. access_control($this);
  375. $schooldetails = $this->session->userdata('schoolinfo');
  376.  
  377. # Get the passed details into the url data array if any
  378. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  379. # Pick all assigned data
  380. $data = assign_to_data($urldata);
  381.  
  382. #Get the paginated list of the deals
  383. $data = paginate_list($this, $data, 'get_stock_items_list', array('isactive'=>'Y', 'searchstring'=>' s.school = '.$schooldetails['id']));
  384.  
  385. $data = add_msg_if_any($this, $data);
  386. $this->load->view('library/manage_stock_item_view', $data);
  387. }
  388.  
  389. function manage_returns(){
  390. access_control($this);
  391. $schooldetails = $this->session->userdata('schoolinfo');
  392.  
  393. # Get the passed details into the url data array if any
  394. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  395. # Pick all assigned data
  396. $data = assign_to_data($urldata);
  397.  
  398. #Get the paginated list of the deals
  399. $data = paginate_list($this, $data, 'get_borrower_list', array('isactive'=>'Y', 'searchstring'=>' b.school = '.$schooldetails['id']));
  400.  
  401. $data = add_msg_if_any($this, $data);
  402. $this->load->view('library/manage_borrowers_view', $data);
  403. }
  404.  
  405. function manage_borrowers(){
  406. access_control($this);
  407. $schooldetails = $this->session->userdata('schoolinfo');
  408.  
  409. # Get the passed details into the url data array if any
  410. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  411. # Pick all assigned data
  412. $data = assign_to_data($urldata);
  413.  
  414. #Get the paginated list of the returns
  415. $data = paginate_list($this, $data, 'get_return_list', array('isactive'=>'Y', 'searchstring'=>' b.school = '.$schooldetails['id']));
  416.  
  417. $data['returned'] = $data['page_list'];
  418.  
  419. $data = paginate_list($this, $data, 'get_borrower_list', array('isactive'=>'Y','school'=>$schooldetails['id'], 'searchstring'=>'1'));
  420. $data['all'] = $data['page_list'];
  421.  
  422. $data = add_msg_if_any($this, $data);
  423. $this->load->view('library/manage_returns_view', $data);
  424. }
  425.  
  426. function delete_borrower(){
  427. access_control($this);
  428.  
  429. # Get the passed details into the url data array if any
  430. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  431. # Pick all assigned data
  432. $data = assign_to_data($urldata);
  433.  
  434. $save_result = $this->db->query($this->Query_reader->get_query_by_code('delete_row', array('tname' => "borrowers",'id' => decryptValue($data['i'])) ));
  435.  
  436.  
  437. if($save_result)
  438. {
  439. $data['msg'] = "The borrower has been deleted.";
  440. //die($data['msg']);
  441. $this->session->set_userdata('sres', $data['msg']);
  442.  
  443. redirect(base_url()."library/manage_borrowers/m/sres");
  444. }
  445. else
  446. {
  447. $data['msg'] = "ERROR: The borrower was not deleted. Please contact your administrator.";
  448. die($data['msg']);
  449. }
  450. }
  451.  
  452. function delete_return(){
  453. access_control($this);
  454.  
  455. # Get the passed details into the url data array if any
  456. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  457. # Pick all assigned data
  458. $data = assign_to_data($urldata);
  459. $data['table'] = "borroweditems";
  460. if(delete_row($this, $data))
  461. {
  462. $save_result = $this->db->query($this->Query_reader->get_query_by_code('update_library',array('item' => $data['i'], 'isavailable' => '0')));
  463. if($save_result){
  464. $data['msg'] = "The return has been deleted.";
  465. //die($data['msg']);
  466. $this->session->set_userdata('sres', $data['msg']);
  467.  
  468. redirect(base_url()."library/manage_returns/m/sres");
  469. }
  470. else
  471. $data['msg'] = "ERROR: The borrower was not deleted. Please contact your administrator.";
  472. }
  473. else
  474. {
  475. $data['msg'] = "ERROR: The borrower was not deleted. Please contact your administrator.";
  476. }
  477. }
  478.  
  479. function delete_stock(){
  480. access_control($this);
  481.  
  482. # Get the passed details into the url data array if any
  483. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  484. # Pick all assigned data
  485. $data = assign_to_data($urldata);
  486.  
  487. $save_result = $this->db->query($this->Query_reader->get_query_by_code('delete_row', array('tname' => "librarystock",'id' => decryptValue($data['i'])) ));
  488.  
  489.  
  490. if($save_result)
  491. {
  492. $data['msg'] = "The stock has been deleted.";
  493. //die($data['msg']);
  494. $this->session->set_userdata('sres', $data['msg']);
  495.  
  496. redirect(base_url()."library/manage_stock/m/sres");
  497. }
  498. else
  499. {
  500. $data['msg'] = "ERROR: The stock was not deleted. Please contact your administrator.";
  501. die($data['msg']);
  502. }
  503. }
  504.  
  505. function delete_stock_item(){
  506. access_control($this);
  507.  
  508. # Get the passed details into the url data array if any
  509. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  510. # Pick all assigned data
  511. $data = assign_to_data($urldata);
  512.  
  513. die($this->Query_reader->get_query_by_code('delete_row', array('tname' => "library",'id' => decryptValue($data['i'])) ));
  514. $save_result = $this->db->query($this->Query_reader->get_query_by_code('delete_row', array('tname' => "library",'id' => decryptValue($data['i'])) ));
  515.  
  516.  
  517. if($save_result)
  518. {
  519. $data['msg'] = "The stock item has been deleted.";
  520. //die($data['msg']);
  521. $this->session->set_userdata('sres', $data['msg']);
  522.  
  523. redirect(base_url()."library/manage_stock_items/m/sres");
  524. }
  525. else
  526. {
  527. $data['msg'] = "ERROR: The stock item was not deleted. Please contact your administrator.";
  528. die($data['msg']);
  529. }
  530. }
  531.  
  532. function generate_report(){
  533. access_control($this);
  534. $schooldetails = $this->session->userdata('schoolinfo');
  535. # Get the passed details into the url data array if any
  536. $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
  537. # Pick all assigned data
  538. $data = assign_to_data($urldata);
  539.  
  540. if($this->input->post('generatepdf') || $this->input->post('generateexcel')){
  541. $required_fields = array('type');
  542. $_POST = clean_form_data($_POST);
  543. $validation_results = validate_form('', $_POST, $required_fields);
  544.  
  545. if($validation_results['bool'])
  546. {
  547. $_POST = clean_form_data($_POST);
  548. $searchstring='1';
  549.  
  550. if($_POST['type'] == 7){
  551.  
  552. if(isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "")
  553. $searchstring .= " AND UNIX_TIMESTAMP(b.datetaken) <= '".strtotime($_POST['dateto'].' 23:59:59')."' AND UNIX_TIMESTAMP(b.datetaken) >= '".(strtotime($_POST['datefrom']) - 86400)."'";
  554. if(isset($_POST['item']) && $_POST['item'] != "")
  555. $searchstring .= " AND b.stockid=".$_POST['item'];
  556.  
  557. $data['dateto'] = $_POST['dateto'];
  558. $data['datefrom'] = $_POST['datefrom'];
  559. #Get the paginated list of the purchases
  560. $data = paginate_list($this, $data, 'get_borrower_list', array('isactive'=>'Y', 'searchstring'=>' b.school = '.$schooldetails['id'].' AND ('.$searchstring.')'));
  561. $report_type = 'borrowing_report';
  562. $report_name = "BORROWING REPORT";
  563.  
  564. if($this->input->post('generateexcel')){
  565. $size = sizeof($data['page_list']);
  566. $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][($size-1)]['datetaken']));
  567. $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datetaken']));
  568. if(!empty($data['datefrom']))
  569. $from = date("j M, Y", GetTimeStamp($data['datefrom']));
  570. else
  571. $from = $maxdate;
  572.  
  573. if(!empty($data['dateto']))
  574. $to = date("j M, Y", GetTimeStamp($data['dateto']));
  575. else
  576. $to = $mindate;
  577.  
  578. $mydata = array($schooldetails['schoolname']);
  579. $this->excelexport->addRow($mydata);
  580. $mydata = array($report_name, "", "", "From :", $from,"","To :", $to);
  581. $this->excelexport->addRow($mydata);
  582. $mydata = array("Date Borrowed","Title", "Returned / Borrowed", "Name", "Date Expected");
  583. $this->excelexport->addRow($mydata);
  584. foreach($data['page_list'] AS $row){
  585. #check expiry of rental period
  586. $currentdate = date("Y-m-d H:i:s");
  587. $borrower_status = check_borrower_status($this, $row['borrowerid']);
  588.  
  589. $mydata = array(date("j M, Y", GetTimeStamp($row['datetaken'])), $row['stocktitle'], ($row['copiestaken'] - $borrower_status)."/".$row['copiestaken'], $row['firstname']." ".$row['lastname'], date("j M, Y", GetTimeStamp($row['returndate'])));
  590. $this->excelexport->addRow($mydata);
  591. }
  592. }
  593. }
  594.  
  595. elseif($_POST['type'] == 5){
  596.  
  597. if(isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "")
  598. $searchstring .= " AND UNIX_TIMESTAMP(l.createdon) <= '".strtotime($_POST['dateto'].' 23:59:59')."' AND UNIX_TIMESTAMP(l.createdon) >= '".(strtotime($_POST['datefrom']) - 86400)."'";
  599. if(isset($_POST['item']) && $_POST['item'] != "")
  600. $searchstring .= " AND i.itemid=".$_POST['item'];
  601.  
  602. $data['dateto'] = $_POST['dateto'];
  603. $data['datefrom'] = $_POST['datefrom'];
  604. #Get the paginated list of the purchases
  605. $data = paginate_list($this, $data, 'get_stock_items_list', array('isactive'=>'Y', 'searchstring'=>' s.school = '.$schooldetails['id'].' AND ('.$searchstring.')'));
  606. $report_type = 'library_stock_report';
  607. $report_name = "LIBRARY STOCK REPORT";
  608.  
  609. if($this->input->post('generateexcel')){
  610. $size = sizeof($data['page_list']);
  611. $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][($size-1)]['datecreated']));
  612. $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datecreated']));
  613. if(!empty($data['datefrom']))
  614. $from = date("j M, Y", GetTimeStamp($data['datefrom']));
  615. else
  616. $from = $maxdate;
  617.  
  618. if(!empty($data['dateto']))
  619. $to = date("j M, Y", GetTimeStamp($data['dateto']));
  620. else
  621. $to = $mindate;
  622.  
  623. $mydata = array($schooldetails['schoolname']);
  624. $this->excelexport->addRow($mydata);
  625. $mydata = array($report_name, "", "", "From :", $from,"","To :", $to);
  626. $this->excelexport->addRow($mydata);
  627. $mydata = array("Date Added","Serial Number", "Title", "ISBN Number");
  628. $this->excelexport->addRow($mydata);
  629. foreach($data['page_list'] AS $row){
  630. $mydata = array(date("j M, Y", GetTimeStamp($row['datecreated'])), $row['serialnumber'], $row['stocktitle'], $row['isbnnumber']);
  631. $this->excelexport->addRow($mydata);
  632. }
  633. }
  634. }
  635.  
  636. elseif($_POST['type'] == 4){
  637. #Get the paginated list of the inventory
  638. $data = paginate_list($this, $data, 'get_stock_list', array('isactive'=>'Y', 'searchstring'=>' school = '.$schooldetails['id']));
  639. $report_type = 'library_report';
  640. $report_name = "LIBRARY REPORT";
  641.  
  642. if($this->input->post('generateexcel')){
  643. $mydata = array($schooldetails['schoolname']);
  644. $this->excelexport->addRow($mydata);
  645. $mydata = array($report_name, "", "", "", date("j M, Y", time()));
  646. $this->excelexport->addRow($mydata);
  647. $mydata = array("Date", "Title", "Stocked", "Available", "Out");
  648. $this->excelexport->addRow($mydata);
  649. foreach($data['page_list'] AS $row){
  650. $stocked = get_all_stock_items($this, $row['id']);
  651. $in = get_stock_items($this, $row['id'], 1);
  652. $out = get_stock_items($this, $row['id'], 0);
  653.  
  654. $mydata = array(date("j M, Y", GetTimeStamp($row['createdon'])), $row['stocktitle'], $stocked, $in, $out);
  655. $this->excelexport->addRow($mydata);
  656. }
  657. }
  658. }
  659.  
  660. elseif($_POST['type'] == 8){
  661.  
  662. if(isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "")
  663. $searchstring .= " AND UNIX_TIMESTAMP(r.returndate) <= '".strtotime($_POST['dateto'].' 23:59:59')."' AND UNIX_TIMESTAMP(r.returndate) >= '".(strtotime($_POST['datefrom']) - 86400)."'";
  664. if(isset($_POST['item']) && $_POST['item'] != "")
  665. $searchstring .= " AND s.id=".$_POST['item'];
  666.  
  667. $data['dateto'] = $_POST['dateto'];
  668. $data['datefrom'] = $_POST['datefrom'];
  669. #Get the paginated list of the purchases
  670. $data = paginate_list($this, $data, 'get_return_list', array('isactive'=>'Y', 'searchstring'=>' b.school = '.$schooldetails['id'].' AND ('.$searchstring.')'));
  671.  
  672. $report_type = 'returning_report';
  673.  
  674. $report_name = "RETURNING REPORT";
  675.  
  676. if($this->input->post('generateexcel')){
  677. $size = sizeof($data['page_list']);
  678. $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][($size-1)]['returndate']));
  679. $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['returndate']));
  680. if(!empty($data['datefrom']))
  681. $from = date("j M, Y", GetTimeStamp($data['datefrom']));
  682. else
  683. $from = $maxdate;
  684.  
  685. if(!empty($data['dateto']))
  686. $to = date("j M, Y", GetTimeStamp($data['dateto']));
  687. else
  688. $to = $mindate;
  689.  
  690. $mydata = array($schooldetails['schoolname']);
  691. $this->excelexport->addRow($mydata);
  692. $mydata = array($report_name, "", "", "From :", $from,"","To :", $to);
  693. $this->excelexport->addRow($mydata);
  694. $mydata = array("Date Returned","Title", "Serial Number");
  695. $this->excelexport->addRow($mydata);
  696. foreach($data['page_list'] AS $row){
  697.  
  698. $mydata = array(date("j M, Y", GetTimeStamp($row['returndate'])), $row['stocktitle'], $row['stocktitle'],$row['serialnumber']);
  699. $this->excelexport->addRow($mydata);
  700. }
  701. }
  702. }
  703.  
  704.  
  705.  
  706. #Format the statement
  707. $report_html = '';
  708. #$financial_details = array();
  709.  
  710. $this->load->library('parser');
  711.  
  712. $data['schoolname'] = $schooldetails['schoolname'];
  713. $data['report_html'] = $report_html;
  714. $output = $this->parser->parse('reports/'.$report_type,$data,true);
  715.  
  716. if($this->input->post('generatepdf'))
  717. gen_pdf($this, $output);
  718. else{
  719.  
  720. $this->excelexport->download($report_type.'.xls');
  721. }
  722. }
  723. if((empty($validation_results['bool']) || (!empty($validation_results['bool']) && !$validation_results['bool']))
  724. && empty($data['msg']) )
  725. {
  726. $data['msg'] = "WARNING: The highlighted fields are required.";
  727. }
  728.  
  729. $data['requiredfields'] = $validation_results['requiredfields'];
  730. $data['formdata'] = $_POST;
  731. }
  732. $this->load->view('library/new_report_view');
  733.  
  734. }
  735. }
  736. ?>
  737.  
  738.  
  739. the View
  740.  
  741. <?php
  742. if(empty($requiredfields)){
  743. $requiredfields = array();
  744. }
  745.  
  746. $indicator = (!empty($isview))? "": "<span class='redtext'>*</span>";?>
  747.  
  748. <table border="0" cellspacing="0" cellpadding="10" width="100%" id='contenttable'>
  749. <tr>
  750. <td colspan="2" style="padding-top:0px;" class="pageheader">
  751. <table>
  752. <tr>
  753. <td valign="middle"><div class="page-title">Borrower Details</div></td>
  754. <td valign="middle">&nbsp;</td>
  755. <td valign="middle">&nbsp;</td>
  756. </tr>
  757. </table>
  758. </td>
  759. </tr>
  760. <tr>
  761. <td colspan="2" style="padding-top:0px;" class="pageheader">
  762. <div class="grey_ruler"></div>
  763. </td>
  764. </tr>
  765.  
  766. <?php
  767. if(isset($msg)){
  768. echo "<tr><td colspan='4'>".format_notice($msg)."</td></tr>";
  769. }
  770. ?>
  771.  
  772. <tr>
  773. <td valign="top">
  774. <form id="form1" name="form1" method="post" action="<?php echo base_url();?>library/load_borrower_form<?php
  775. if(!empty($i))
  776. {
  777. echo "/i/".$i;
  778. }
  779. //print_r($stockdata);
  780. echo "/s/".encryptValue($stockdata['stockid']);
  781. ?>" >
  782.  
  783. <table width="100" border="0" cellspacing="0" cellpadding="8">
  784. <tr>
  785. <td valign="top" nowrap="nowrap" class="label" style="padding-top:13px">Item :</td>
  786. <td class="field" nowrap>
  787. <?php
  788. echo "<span class='viewtext'>".$stockdata['stocktitle']." by ".$stockdata['author']."</span>";
  789. ?>
  790. </td>
  791.  
  792. </tr>
  793. <input type="hidden" name="stockid" value="<?php echo $stockdata['stockid']; ?>" />
  794. <tr>
  795. <td valign="top" nowrap="nowrap" class="label" style="padding-top:13px">Borrower :<?php echo $indicator;?></td>
  796. <td class="field" nowrap>
  797. <?php
  798. if(!empty($isview))
  799. {
  800. echo "<span class='viewtext'>".$formdata['firstname']." ".$formdata['middlename']." ".$formdata['lastname']."</span>";
  801. }else{
  802. echo get_required_field_wrap($requiredfields, 'search');
  803. ?>
  804. <input name="search" type="text" id="search" size="35" class="textfield" value="<?php
  805. if(!empty($formdata['firstname']) && !empty($formdata['middlename']) && !empty($formdata['lastname'])){
  806. echo $formdata['firstname']." ".$formdata['middlename']." ".$formdata['lastname'];
  807. }?>" onkeyup="startInstantSearch('search', 'searchby', '<?php echo base_url();?>search/load_results/type/student_list/layer/searchresults2/area/select_student');showPartLayer('searchresults2', 'fast');" onkeypress="return handleEnter(this, event)"/>
  808. <?php echo get_required_field_wrap($requiredfields, 'search', 'end'); }?>
  809. <div id="searchresults2" style='max-height: 380px; overflow:hidden; position:absolute;border: 1px solid #98CBFF; background-color: #F7F7F7; display:none;'></div></td>
  810. <td>&nbsp;<input name="searchby" type="hidden" id="searchby" value="firstname__lastname__middlename__studentno" /></td>
  811. </tr>
  812. <input id="studentid" type="hidden" name="studentid" value="<?php
  813. if(!empty($formdata['studentid'])){
  814. echo $formdata['studentid'];
  815. }; ?>" />
  816.  
  817. <tr>
  818. <td valign="top" nowrap="nowrap" class="label" style="padding-top:13px">Issue Date :<?php echo $indicator;?></td>
  819. <td class="field" nowrap>
  820. <?php
  821. if(!empty($isview))
  822. {
  823. echo "<span class='viewtext'>".$formdata['datetaken']."</span>";
  824. }else{
  825. echo get_required_field_wrap($requiredfields, 'datetaken');
  826. ?>
  827. <input type="text" name="datetaken" id="datetaken" class="textfield manyyearsdatefield" size="30" value="<?php
  828. if(!empty($formdata['datetaken'])){
  829. echo $formdata['datetaken'];
  830. }?>"/>
  831. <?php echo get_required_field_wrap($requiredfields, 'datetaken', 'end');
  832. }
  833. ?>
  834. </td>
  835. </tr>
  836.  
  837. <tr>
  838. <td valign="top" nowrap="nowrap" class="label" style="padding-top:13px">Expected Date :<?php echo $indicator;?></td>
  839. <td class="field" nowrap>
  840. <?php
  841. if(!empty($isview))
  842. {
  843. echo "<span class='viewtext'>".$formdata['returndate']."</span>";
  844. }else{
  845. echo get_required_field_wrap($requiredfields, 'returndate');
  846. ?>
  847. <input type="text" name="returndate" id="returndate" class="textfield manyyearsdatefield" size="30" value="<?php
  848. if(!empty($formdata['returndate'])){
  849. echo $formdata['returndate'];
  850. }?>"/>
  851. <?php echo get_required_field_wrap($requiredfields, 'returndate', 'end');
  852. }
  853. ?>
  854. </td>
  855. </tr>
  856. <tr>
  857. <td valign="top" nowrap="nowrap" class="label" style="padding-top:13px">Item(s) :<?php echo $indicator;?></td>
  858. <td nowrap><?php
  859. echo get_required_field_wrap($requiredfields, 'item');?>
  860. <select name="items[]" multiple="multiple" class="textfield" style="height:200px; width:270px;" >
  861. <?php
  862. if(!empty($isview))
  863. write_options_list($this,array('tname' => "library", 'searchstring'=>" WHERE stockid =".$stockdata['stockid']),'','serialnumber');
  864. else
  865. write_options_list($this,array('tname' => "library", 'searchstring'=>" WHERE stockid =".$stockdata['stockid']." AND isavailable=1"),'','serialnumber');
  866. ?>
  867. </select>
  868. <?php echo get_required_field_wrap($requiredfields, 'item', 'end');
  869.  
  870.  
  871. ?></td>
  872. </tr>
  873. <?php if(empty($isview)){ ?>
  874. <tr>
  875. <td>&nbsp;</td>
  876. <td><input type="submit" name="saveborrower" id="login" value="Save" class="button"/></td>
  877. <td>&nbsp;</td>
  878. </tr>
  879. <?php } ?>
  880. </table>
  881.  
  882. </form>
  883.  
  884. </td>
  885. </tr>
  886.  
  887. </table>
RAW Paste Data