PageRenderTime 61ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/modules/users/credit_customer_2.php

https://bitbucket.org/shaileshmyid/tikvah
PHP | 521 lines | 420 code | 77 blank | 24 comment | 64 complexity | 35fb32ed86be38830b205a55abe9f033 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?
  2. session_start();
  3. if(!isset($_SESSION['login']))
  4. {
  5. header('Location: index.php');
  6. exit;
  7. }
  8. $where = " WHERE credit_customer !=1 AND credit_customer !=0";
  9. ########################################### PAGING WITH PER PAGE #####################################
  10. $file_name = "index"; // this is file name which is used during paging , included at the bottom of the page
  11. $paging_table_name = "user";
  12. $paging_query = $where;
  13. $next_page_condition = "&page=credit_customer";
  14. include("paging/paging_query.inc.php");
  15. ############################################ END PAGING WITH PER PAGE ##############################################
  16. if(!isset($_REQUEST['action']))
  17. {
  18. $sql = "SELECT * FROM user WHERE credit_customer !=1 AND credit_customer !=0 ORDER BY email LIMIT $eu, $limit ";
  19. $result = mysql_query($sql);
  20. $num_rows = mysql_num_rows($result);
  21. }
  22. if(isset($_REQUEST['email']) && $_REQUEST['email']!='')
  23. {
  24. $email = $_REQUEST['email'];
  25. $query2 = "SELECT * FROM user where email like '%$email%' order by email ";
  26. $rec = mysql_query($query2);
  27. $nume = mysql_num_rows($rec);
  28. $email = $_REQUEST['email'];
  29. $sql = "SELECT * FROM user where email like '%$email%' order by email LIMIT $eu, $limit ";
  30. $result = mysql_query($sql);
  31. $num_rows = mysql_num_rows($result);
  32. }
  33. ################################# DELETE #########################################
  34. if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete')
  35. {
  36. $id = $_REQUEST['id'];
  37. $sql = "delete from user where id='$id' ";
  38. $result = mysql_query($sql);
  39. if(isset($_REQUEST['email']) && $_REQUEST['email']!='')
  40. {
  41. $query2 = "SELECT * FROM user where first_name like '$email%' order by email ";
  42. $rec = mysql_query($query2);
  43. $nume = mysql_num_rows($rec);
  44. $login = $_REQUEST['email'];
  45. $sql = "SELECT * FROM user where first_name like '$email%' order by email ";
  46. $result = mysql_query($sql);
  47. $num_rows = mysql_num_rows($result);
  48. }else{
  49. header("location: ?page=credit_customer");
  50. }
  51. }
  52. ################################# END DELETE #########################################
  53. ################################# DELETE MORE #########################################
  54. if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete_more')
  55. {
  56. $len = count($_REQUEST['check']);
  57. for($i=0;$i<$len;$i++)
  58. {
  59. $sql = mysql_query("delete from user where id = '".$_REQUEST['check'][$i]."' ");
  60. }
  61. $sql = mysql_query("select * from user ORDER BY email LIMIT $eu, $limit ");
  62. $num_rows = mysql_num_rows($sql);
  63. if(isset($_REQUEST['after_search']) && $_REQUEST['after_search']!='')
  64. {
  65. $email = $_REQUEST['after_search'];
  66. $sql = "SELECT * FROM user where first_name like '$email%' order by email LIMIT $eu, $limit ";
  67. $result = mysql_query($sql);
  68. $num_rows = mysql_num_rows($result);
  69. }else{
  70. $sql = "SELECT * FROM user ORDER BY first_name LIMIT $eu, $limit ";
  71. $result = mysql_query($sql);
  72. $num_rows = mysql_num_rows($result);
  73. }
  74. }
  75. ################################# END DELETE MORE #########################################
  76. ################################# SUSPEND MORE #########################################
  77. if(isset($_REQUEST['action']) && $_REQUEST['action']=='suspend_more')
  78. {
  79. $len = count($_REQUEST['check']);
  80. for($i=0;$i<$len;$i++)
  81. {
  82. $sql = "UPDATE user set status='0' where id='".$_REQUEST['check'][$i]."' ";
  83. $result = mysql_query($sql);
  84. }
  85. $sql = mysql_query("select * from user ORDER BY email LIMIT $eu, $limit ");
  86. $num_rows = mysql_num_rows($sql);
  87. if(isset($_REQUEST['after_search']) && $_REQUEST['after_search']!='')
  88. {
  89. //$login = $_REQUEST['after_search'];
  90. $email = $_REQUEST['after_search'];
  91. $sql = "SELECT * FROM user where first_name like '$email%' order by email LIMIT $eu, $limit ";
  92. $result = mysql_query($sql);
  93. $num_rows = mysql_num_rows($result);
  94. }else{
  95. $sql = "SELECT * FROM user ORDER BY email LIMIT $eu, $limit ";
  96. $result = mysql_query($sql);
  97. $num_rows = mysql_num_rows($result);
  98. }
  99. }
  100. ################################# END SUSPEND MORE #########################################
  101. ################################# ACTIVE MORE #########################################
  102. if(isset($_REQUEST['action']) && $_REQUEST['action']=='active_more')
  103. {
  104. $len = count($_REQUEST['check']);
  105. for($i=0;$i<$len;$i++)
  106. {
  107. $sql = "UPDATE user set status='1' where id='".$_REQUEST['check'][$i]."' ";
  108. $result = mysql_query($sql);
  109. }
  110. $sql = mysql_query("select * from user ORDER BY email LIMIT $eu, $limit ");
  111. $num_rows = mysql_num_rows($sql);
  112. if(isset($_REQUEST['after_search']) && $_REQUEST['after_search']!='')
  113. {
  114. //$email = $_REQUEST['after_search'];
  115. $email = $_REQUEST['after_search'];
  116. $sql = "SELECT * FROM user where first_name like '$email%' order by email LIMIT $eu, $limit ";
  117. $result = mysql_query($sql);
  118. $num_rows = mysql_num_rows($result);
  119. }else{
  120. $sql = "SELECT * FROM user ORDER BY email LIMIT $eu, $limit ";
  121. $result = mysql_query($sql);
  122. $num_rows = mysql_num_rows($result);
  123. }
  124. }
  125. ################################# END ACTIVE MULTIPLE RECORDS #########################################
  126. ################################# STATUS CHANGE #########################################
  127. if(isset($_REQUEST['status']))
  128. {
  129. $id = $_REQUEST['id'];
  130. $status = $_REQUEST['status'];
  131. if($status=='1')
  132. {
  133. $sql = "UPDATE user SET status='0' where id='$id' ";
  134. $result = mysql_query($sql);
  135. }else{
  136. $sql = "UPDATE user SET status='1' where id='$id' ";
  137. $result = mysql_query($sql);
  138. }
  139. if($_REQUEST['email']!='')
  140. {
  141. $sql = "SELECT * FROM user where id='$id' ORDER BY email LIMIT $eu, $limit";
  142. }
  143. else
  144. {
  145. $sql = "SELECT * FROM user ORDER BY email LIMIT $eu, $limit";
  146. }
  147. $result = mysql_query($sql);
  148. $num_rows = mysql_num_rows($result);
  149. }
  150. ################################# END STATUS CHANGE #########################################
  151. ?>
  152. <td width="100%" align="center" valign="top" bgcolor="" class="red">
  153. <table width="100%" border="0" align="center" cellpadding="0"
  154. cellspacing="0" bordercolor="#000000">
  155. <tr>
  156. <td valign="middle" height="20" align="left">
  157. <table width="767" border="0" cellspacing="0" cellpadding="0">
  158. <tr>
  159. <td width="399" height="30" class="head_ing">Credit Customers</td>
  160. <td width="368" align="right">&nbsp;</td>
  161. </tr>
  162. </table>
  163. </td>
  164. </tr>
  165. <tr>
  166. <td bordercolor="#FFFFFF" valign="top" align="center">
  167. <form name="form1" method="post" action="?page=credit_customer">
  168. <table width="100%" border="0" cellspacing="4" cellpadding="0">
  169. <? if(isset($_REQUEST['message'])) {?>
  170. <tr align="center">
  171. <td colspan="7" class="red style1"><?=$_REQUEST['message'];?></td>
  172. </tr>
  173. <? } ?>
  174. <tr>
  175. <td align="center" valign="top">
  176. <table width="100%%" border="0" align="center" cellpadding="3"
  177. cellspacing="1" bgcolor="#CCCCCC">
  178. <tr align="center" bgcolor="#ffffff">
  179. <td height="25" colspan="10" align="left" bgcolor="#FFFFFF">
  180. <table width="100%" border="0" height="15">
  181. <tr>
  182. <td width="316" height="15">
  183. <div align="right">Search by Email</div>
  184. </td>
  185. <td width="368">
  186. <div align="left"><label> <input name="email" type="text"
  187. id="email" value="<?=$_REQUEST['email'];?>"> </label> <label>&nbsp;&nbsp;
  188. <input type="submit" name="Submit" value="Search"> </label> <? //include("paging/no_of_records.inc.php"); ?>
  189. </div>
  190. </td>
  191. </tr>
  192. </table>
  193. </td>
  194. </tr>
  195. <tr align="center" bgcolor="#000000">
  196. <!--<td width="11%" height="25" align="left" class="white" >Login Name </td>-->
  197. <td width="10%" class="white">Email</td>
  198. <td width="8%" height="25" class="white">Name</td>
  199. <!-- <td width="13%" class="white">Address</td> -->
  200. <td width="10%" class="white"><span>City</span></td>
  201. <!--<td width="13%" class="white">Password</td> -->
  202. <td width="10%" class="white">Phone</td>
  203. <td width="10%" class="white">Credit Customer</td>
  204. <td width="10%" class="white">Payment History</td>
  205. <td width="10%" class="white">Status</td>
  206. <td width="8%" class="white">Delete</td>
  207. <!-- <td width="9%" ><div align="center"><span class="white">Status</td> -->
  208. <!--<td width="9%" ><div class="white">Edit</div></td> -->
  209. <td width="7%" class="white">Select</td>
  210. </tr>
  211. <?
  212. if($result){
  213. while($row=mysql_fetch_array($result))
  214. {?>
  215. <tr align="center" bgcolor="#f5f5f5">
  216. <!--<td height="33" align="center" bgcolor="#FFFFFF"><div align="center">
  217. <?=ucfirst($row['login'])?>
  218. </td>-->
  219. <td align="left" bgcolor="#FFFFFF"><?=$row['email'];?>
  220. </td>
  221. <td align="center" bgcolor="#FFFFFF"><?=ucfirst($row['first_name'])?>
  222. </td>
  223. <!-- <td align="center" bgcolor="#FFFFFF"><?=$row['address'];?>
  224. </td> -->
  225. <td align="center" bgcolor="#FFFFFF"><?=ucfirst($row['city']);?>
  226. </td>
  227. <!-- <td align="center" bgcolor="#FFFFFF"><?=$row['password']?> -->
  228. </td>
  229. <td height="33" align="center" bgcolor="#FFFFFF"><?=ucfirst($row['telephone'])?></td>
  230. <td height="33" align="center" bgcolor="#FFFFFF">
  231. <?php
  232. if($row['credit_customer'] == 0){
  233. $display_credit_customer = "No";
  234. }elseif($row['credit_customer'] == 1){
  235. $display_credit_customer = "Assign limit";
  236. }else{
  237. $display_credit_customer = $row['credit_customer'];
  238. }
  239. ?>
  240. <a title="<?=$row['email']?>" id="<?=$row['id']?>" class="credit_customer" href="#"><?php echo $display_credit_customer; ?></a>
  241. </td>
  242. <td height="33" align="center" bgcolor="#FFFFFF">
  243. <?php
  244. if($row['credit_customer'] != 0 && $row['credit_customer'] != 1){
  245. echo "<a href='?page=payment&user_id=$row[id]'> View </a>";
  246. }
  247. ?>
  248. </td>
  249. <td align="center" bgcolor="#FFFFFF"><a
  250. href="?page=credit_customer&status=<?=$row['status']?>&id=<?=$row['id']?>&email=<?=$_REQUEST['email'];?>">
  251. <? echo ($row['status'] == 1)? "Active" : "Suspended"; ?> </a>
  252. </td>
  253. <td width="8%" align="center" bgcolor="#FFFFFF"><a
  254. href="?page=credit_customer&action=delete&id=<?=$row['id']; if(isset($email)){?>&email=<?=$email;}?>"
  255. onClick=" javascript: return confirm('Are you sure You want to Delete User ');"><img
  256. src="../images/del.gif" border="0" /></a>
  257. </td>
  258. <!--<td height="33" align="center" bgcolor="#FFFFFF" ><a href="user.php?status=<?=$row['status']; ?>&id=<?=$row['id']; ?>"><?=ucfirst($row['status'])?></a>
  259. </td> -->
  260. <!--<td height="33" align="left" bgcolor="#FFFFFF"><div align="center"><a href="add_new_city.php?action=edit&city_id=<?=$row['id'];?>"><img src="images/Edit.gif" width="12" height="12" border="0" /></a></td> -->
  261. <td width="7%" align="center" bgcolor="#FFFFFF"><input
  262. type="checkbox" name="check[]" id="check"
  263. value="<?=$row['id']?>"></td>
  264. </tr>
  265. <? }
  266. }else{?>
  267. <tr bgcolor="#FFFFFF">
  268. <td height="33" colspan="15" align="center" bgcolor="#ffffff"
  269. class="red style1">No User Exists</td>
  270. </tr>
  271. <? }?>
  272. <tr bgcolor="#FFFFFF">
  273. <td height="20" colspan="15" align="right" bgcolor="#ffffff">
  274. <div id="text_message" align="right" class="bod-text">Check all</div>
  275. <input type="checkbox" name="check_abc" onClick="select_all();">&nbsp;&nbsp;&nbsp;&nbsp;
  276. </td>
  277. </tr>
  278. <tr bgcolor="#000000">
  279. <td height="33" colspan="15" align="right">
  280. <div align="right"><input type="hidden" name="after_search"
  281. value="<?=$email;?>">
  282. &nbsp;&nbsp;&nbsp; <input type="button" name="button222"
  283. value="Show All" onClick="javascript:window.location='?page=credit_customer'">
  284. &nbsp;&nbsp;&nbsp; <input type="button" name="button22"
  285. value="Suspend" onClick="do_more('suspend_more');">
  286. &nbsp;&nbsp;&nbsp; <input type="button" name="button2"
  287. value="Active" onClick="do_more('active_more');">
  288. &nbsp;&nbsp;&nbsp; <input type="button" name="button"
  289. value="Delete" onClick="do_more('delete_more');"></div>
  290. </td>
  291. </tr>
  292. <!-- Paging starts here -->
  293. <? include("paging/paging_row.inc.php") ?>
  294. <!-- Paging ends starts here -->
  295. </table>
  296. </td>
  297. </tr>
  298. </table>
  299. </form>
  300. </td>
  301. </tr>
  302. </table>
  303. </td>
  304. <div class="overlay">
  305. <div class="confirmbox"></div>
  306. </div>
  307. <script language="JavaScript">
  308. function navigate(url_page)
  309. {
  310. window.location=url_page;
  311. /*document.form1.action=url_page;
  312. document.form1.submit();
  313. */
  314. }
  315. function select_all()
  316. {
  317. var doc = document.form1;
  318. var len = document.form1.check.length;
  319. if(doc.check_abc.checked==true)
  320. {
  321. if(len){
  322. for(var i=0;i<len;i++){
  323. doc.check[i].checked = true;
  324. }
  325. }else{
  326. doc.check.checked = true;
  327. }
  328. document.getElementById("text_message").innerHTML='Uncheck All';
  329. }
  330. else{
  331. if(len){
  332. for(var i=0;i<len;i++){
  333. doc.check[i].checked = false;
  334. }
  335. }else {
  336. doc.check.checked = false;
  337. }
  338. document.getElementById("text_message").innerHTML='Check All';
  339. }
  340. }
  341. function do_more(action)
  342. {
  343. //alert(action);
  344. var doc = document.form1;
  345. var len = document.form1.check.length;
  346. var flag = 0;
  347. if(len){
  348. for(var i=0;i<len;i++){
  349. //alert(i);
  350. //alert(doc.check[i].checked);
  351. if(doc.check[i].checked == true)
  352. {
  353. flag = 1;
  354. }
  355. }
  356. }
  357. else{
  358. if(doc.check.checked == true){
  359. flag = 1;
  360. }
  361. }
  362. // checking if any checkbox has been checked or not
  363. // if checked then it will call the same page or otherwise display a messagwe
  364. if(flag==1){
  365. if(action=='delete_more'){ // in the case of delete it will ask for confirmation
  366. if(confirm('Do you really want to delete the users')){
  367. document.form1.action="?page=credit_customer&action="+action;
  368. document.form1.submit();
  369. }
  370. }else if(action=='send_newsletter'){
  371. document.form1.action="send_newsletter.php?action="+action;
  372. document.form1.submit();
  373. }else{
  374. document.form1.action="?page=credit_customer&action="+action;
  375. document.form1.submit();
  376. }
  377. }
  378. else{
  379. alert('Please select atleast one checkbox');
  380. }
  381. }
  382. $(function(){
  383. // Show credit limit form
  384. $('.credit_customer').live('click',function(){
  385. var user_id = $(this).attr('id');
  386. var old_credit_value = $(this).text();
  387. var email = $(this).attr('title');
  388. if(old_credit_value == "Assign limit"){
  389. old_credit_value = "";
  390. }else if(old_credit_value == "No"){
  391. old_credit_value = "";
  392. if(!confirm("Request has not been raised to become a credit customer. Do you want to assign Credit limit to this user ?")){
  393. return false;
  394. }
  395. }
  396. var form_data = {'user_id':user_id,'old_credit_value':old_credit_value,'email':email};
  397. $.ajax({
  398. async: false,
  399. type: "POST",
  400. url: site_url+"/modules/users/index.php?page=ajax_actions&action=show_credit_limit_form",
  401. data: form_data,
  402. success: function(result){
  403. $(".overlay").show('slow');
  404. $(".confirmbox").html(result);
  405. }
  406. });
  407. });
  408. //Assign Credit Limit
  409. $('#assign_credit_limit').live('click',function(){
  410. var user_id = $('#user_id').val();
  411. var credit_limit = $('#credit_limit').val();
  412. var email = $('#email').val();
  413. var form_data = {'user_id':user_id,'credit_limit':credit_limit,'email':email};
  414. if(credit_limit == ""){
  415. alert("Please enter Credit limit");
  416. return false;
  417. }else if(isNaN(credit_limit)){
  418. alert("Please enter numbers only in Credit limit")
  419. return false;
  420. }
  421. $.ajax({
  422. async: false,
  423. type: "POST",
  424. url: site_url+"/modules/users/index.php?page=ajax_actions&action=save_credit_limit",
  425. data: form_data,
  426. success: function(result){
  427. var resultObj = jQuery.parseJSON(result);
  428. if(resultObj.status == "success"){
  429. alert(resultObj.message);
  430. if(credit_limit == 0){
  431. $("#"+user_id).text("No");
  432. }else{
  433. $("#"+user_id).text(credit_limit);
  434. }
  435. $('.confirmbox').html('');
  436. $('.overlay').hide('slow');
  437. }else{
  438. alert(resultObj.message);
  439. }
  440. }
  441. });
  442. });
  443. }); // End of main function
  444. </script>