pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP paste-bin - collaborative debugging tool View Help


Posted by Anonymous on Mon 15th Jan 01:26 (modification of post by view diff)
diff | download | new post

  1. <?     
  2. ###----------------------------------------------------------------------------------------------------------------###
  3. ################################################ ===== EVENTS HANDLER ===== ##########################################
  4. ###----------------------------------------------------------------------------------------------------------------###
  5.  
  6. $default_query = "
  7. SELECT
  8. `ord`.`modified` AS `modified`,
  9. `ord`.`alert` AS `alert`,
  10. `ord`.`status` AS `status`,
  11. `ord`.`id` AS `id`,
  12. `ord`.`from` AS `from`,
  13. `ord`.`to` AS `to`,
  14. `ord`.`notes` AS `notes`,
  15. `c`.`name` AS `name`,
  16. `cust`.`name` AS `cust`
  17. FROM
  18. `orders` AS `ord`
  19. Left Join `clients` AS `c` ON (`ord`.`client` = `c`.`id`)
  20. Left Join `orders_customers` AS `cust` ON (`ord`.`id` = `cust`.`orderID`)
  21. WHERE ord.archived='0'
  22.         AND `from` = '".date("Y:m:d")."'
  23.         OR `from` = '".date("Y:m:d", mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")))."'
  24.         ";
  25. if(date("w") == 5)
  26. {
  27.         $default_query .= "OR `from` = '".date("Y:m:d", mktime(0, 0, 0, date("m")  , date("d")+2, date("Y")))."'
  28.         OR `from` = '".date("Y:m:d", mktime(0, 0, 0, date("m")  , date("d")+3, date("Y")))."'";
  29. }
  30. $default_query .= "
  31. /*stat*//*stat*/
  32. GROUP BY ord.id
  33. ORDER BY /*sort*/`name` ASC/*sort*/
  34. ";
  35.  
  36. if(!isset($orders_search_query))
  37.         session_register("orders_search_query");
  38. unset($cond);
  39.  
  40. if($event == 'find')
  41. {
  42.         if($find['what'] == 'all' && $find['str'])
  43.         {
  44.                 for($i = 0; $i < 4; $i++)
  45.                 {
  46.                         //////////////////////////////////////
  47.                         if($find['str'])
  48.                         {
  49.                                 /*
  50.                                 if($i == 0) $find['what'] = 'num';
  51.                                 if($i == 1) $find['what'] = 'accountNr';
  52.                                 if($i == 2) $find['what'] = 'cust';
  53.                                 if($i == 3) $find['what'] = 'bono';
  54.                                 */
  55.                                
  56.                                 switch ($i)
  57.                                 {
  58.                                         case 0:
  59.                                                 $find['what'] = 'num';
  60.                                                 break;
  61.                                         case 1:
  62.                                                 $find['what'] = 'accountNr';
  63.                                                 break;
  64.                                         case 2:
  65.                                                 $find['what'] = 'cust';
  66.                                                 break;
  67.                                         case 3:
  68.                                                 $find['what'] = 'bono';
  69.                                                 break;
  70.                                 }
  71.                                
  72.                                 $str = $find['str'];
  73.                                
  74.                                 $array['num'] = "ord.id LIKE '".$str."'";
  75.                                 $array['accountNr'] = "ord.accountID='".$str."'";
  76.                                 $array['cust'] = "cust.name LIKE '%".$str."%' AND cust.orderID=ord.id";
  77.                                 $array['bono'] = "h.bono LIKE '".$str."' AND h.orderID=ord.id";
  78.                
  79.                                 $cond[] = $array[$find['what']];
  80.                         }
  81.                
  82.                         if($find['from'] && $find['to'])
  83.                                 $cond[] = "ord.`from` >= '".$find['from']."'  AND ord.`to` <= '".$find['to']."'";
  84.                         if($find['alert_from'] && $find['alert_to'])
  85.                                 $cond[] = "(ord.deadline >= '".$find['alert_from']."'  AND ord.deadline <= '".$find['alert_to']."' OR ord.alert >= '".$find['alert_from']."'  AND ord.alert <= '".$find['alert_to']."')";
  86.                         if($find['price_from'] && $find['price_to'])
  87.                         {
  88.                                 $find['price_from'] = validPrice($find['price_from']);
  89.                                 $find['price_to'] = validPrice($find['price_to']);
  90.                                 $cond[] = "ord.price >= '".$find['price_from']."' AND ord.price <= '".$find['price_to']."'";
  91.                         }
  92.                         if($find['client'])
  93.                                 $cond[] = "ord.client='".$find['client']."'";
  94.                         if($find['country'])
  95.                                 $cond[] = "ord.country='".$find['country']."'";
  96.                         if($find['hotel'])
  97.                                 $cond[] = "h.orderID=ord.id AND h.hotel='".$find['hotel']."'";
  98.                         if($find['service'])
  99.                                 $cond[] = "serv.orderID=ord.id AND serv.name='".$find['service']."'";
  100.                
  101.                         if($cond) $cond = ' AND '.implode(' AND ', $cond);
  102.                        
  103.                         $orders_search_query_temp[] = "SELECT ord.modified, ord.alert, ord.status, ord.`id`, ord.`from`, ord.`to`, ord.`notes`, ord.accountID, c.name, cust.name AS cust FROM orders ord, orders_hotels h ".($find['service']?', orders_services serv':'')." LEFT JOIN clients c ON(ord.client=c.id)  LEFT JOIN orders_customers cust ON(ord.id=cust.orderID) WHERE ord.archived='".$deny."' /*stat*//*stat*/ ".$cond." GROUP BY ord.id ORDER BY /*sort*/`from`/*sort*/";
  104.                         //////////////////////////////////////
  105.                 }
  106.                
  107.                 $orders_search_query = '('.implode(') UNION (', $orders_search_query_temp).') GROUP BY ord.id ORDER BY /*sort*/`from`/*sort*/';
  108.         }
  109.         else
  110.         {
  111.                 if($find['str'])
  112.                 {
  113.                         //$str = explode(' ', $find['str']);
  114.                         //while(list($key, $val) = each($str))
  115.                         //{
  116.                         //      if($val) $strBlock[] = $val;
  117.                         //}
  118.                         //$regexpr = implode('|', $strBlock);
  119.        
  120.                         //$array['num'] = "ord.id REGEXP '".$regexpr."'";
  121.                         //$array['accountNr'] = "ord.accountID='".$regexpr."'";
  122.                         //$array['cust'] = "cust.name REGEXP '".$regexpr."' AND cust.orderID=ord.id";
  123.                         //$array['bono'] = "h.bono REGEXP '".$regexpr."' AND h.orderID=ord.id";
  124.                        
  125.                         $str = $find['str'];
  126.                        
  127.                         $array['num'] = "ord.id LIKE '".$str."'";
  128.                         $array['accountNr'] = "ord.accountID='".$str."'";
  129.                         $array['cust'] = "cust.name LIKE '%".$str."%' AND cust.orderID=ord.id";
  130.                         $array['bono'] = "h.bono LIKE '".$str."' AND h.orderID=ord.id";
  131.        
  132.                         if($find['what'])
  133.                                 $cond[] = $array[$find['what']];
  134.                         else
  135.                                 $cond[] = '('.implode(' OR ', $array).')';
  136.                 }
  137.        
  138.                 if($find['from'] && $find['to'])
  139.                         $cond[] = "ord.`from` >= '".$find['from']."'  AND ord.`to` <= '".$find['to']."'";
  140.                 if($find['alert_from'] && $find['alert_to'])
  141.                         $cond[] = "(ord.deadline >= '".$find['alert_from']."'  AND ord.deadline <= '".$find['alert_to']."' OR ord.alert >= '".$find['alert_from']."'  AND ord.alert <= '".$find['alert_to']."')";
  142.                 if($find['price_from'] && $find['price_to'])
  143.                 {
  144.                         $find['price_from'] = validPrice($find['price_from']);
  145.                         $find['price_to'] = validPrice($find['price_to']);
  146.                         $cond[] = "ord.price >= '".$find['price_from']."' AND ord.price <= '".$find['price_to']."'";
  147.                 }
  148.                 if($find['client'])
  149.                         $cond[] = "ord.client='".$find['client']."'";
  150.                 if($find['country'])
  151.                         $cond[] = "ord.country='".$find['country']."'";
  152.                 if($find['hotel'])
  153.                         $cond[] = "h.orderID=ord.id AND h.hotel='".$find['hotel']."'";
  154.                 if($find['service'])
  155.                         $cond[] = "serv.orderID=ord.id AND serv.name='".$find['service']."'";
  156.        
  157.                 if($cond) $cond = ' AND '.implode(' AND ', $cond);
  158.                
  159.                 if($cond)
  160.                 {
  161.                         $orders_search_query = "SELECT ord.modified, ord.alert, ord.status, ord.`id`, ord.`from`, ord.`to`, ord.`notes`, ord.accountID, c.name, cust.name AS cust FROM orders ord, orders_hotels h ".($find['service']?', orders_services serv':'')." LEFT JOIN clients c ON(ord.client=c.id)  LEFT JOIN orders_customers cust ON(ord.id=cust.orderID) WHERE ord.archived='".$deny."' /*stat*//*stat*/ ".$cond." GROUP BY ord.id ORDER BY /*sort*/`from`/*sort*/";
  162.                 }
  163.                 else
  164.                 {
  165.                         $orders_search_query = $default_query;
  166.                 }
  167.         }
  168. }
  169.  
  170. elseif(in_array($sort, array('id', 'from', 'to', 'notes', 'name', 'cust')))
  171. {
  172.         $sort = '`'.$sort.'`';
  173.         preg_match("/\/\*sort\*\/(.*?)\/\*sort\*\//", $orders_search_query, $match);
  174.         if($match[1] == $sort) $sort .= ' DESC';
  175.         $orders_search_query = str_replace($match[0], '/*sort*/'.$sort.'/*sort*/', $orders_search_query);
  176. }
  177.  
  178. elseif($status)
  179. {
  180.         while(list($key, $val) = each($status)) $status[$key] = "ord.`status`='".$val."'";
  181.         $cond = " AND (".implode(' OR ', $status).")";
  182.  
  183.         preg_match("/\/\*stat\*\/(.*?)\/\*stat\*\//", $orders_search_query, $match);
  184.         $orders_search_query = str_replace($match[0], "/*stat*/".$cond."/*stat*/", $orders_search_query);
  185. }
  186.  
  187. elseif($event == 'archive' && $logged_user['orders'] == 3 && $deny == 0)
  188. {
  189.         cleanQueryBuffer();
  190.         @dbQuery("UPDATE orders SET archived=1, modified='".date('Y:m:d:H:i')."' WHERE id IN(".implode(',', $orders).")");
  191.         flushQueryBuffer('Tellimus nr.: '.@implode(',&nbsp;', $orders), 'Arhiveeritud');
  192. }
  193.  
  194. elseif(isset($set_status) && $logged_user['orders'] == 3 && $deny == 0)
  195. {
  196.         cleanQueryBuffer();
  197.         @dbQuery("UPDATE orders SET status='".$set_status."', modified='".date('Y:m:d:H:i')."' WHERE id IN(".implode(',', $orders).")");
  198.         flushQueryBuffer('Tellimus nr.: '.@implode(',&nbsp;', $orders), 'Muudetud status');
  199. }
  200.  
  201.  
  202. ###---------------------------------------------------------------------------------------------------------------###
  203. ################################################ ===== HTML PAGE ===== ##############################################
  204. ###---------------------------------------------------------------------------------------------------------------###
  205.  
  206. $bgcolor = array('#EEEEEE', '#FFDAB2', '#D7E8AB', '#FF4646', '#E5A9AB');
  207.  
  208. if(!$orders_search_query) $orders_search_query = $default_query;
  209. ?>
  210. <html>
  211. <head>
  212. <meta http-equiv="Content-Type" content="text/html; charset=windows-1257">
  213. <meta http-equiv="Content-Language" content="et">
  214. <meta http-equiv="pragma" content="no-cache">
  215. <meta http-equiv="expires" content="0">
  216. <meta http-equiv="cache-control" content="no-cache">
  217. <title>Intranet</title>
  218. <link href="img/style.css" rel=stylesheet>
  219. <SCRIPT src="include/scripts.js" type="text/javascript"></SCRIPT>
  220. </head>
  221. <body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF">
  222.  
  223. <form name="form1" method="POST">
  224. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  225. <?
  226. $result = @mysql_query($orders_search_query);
  227. if($debug=='1')
  228. {
  229.         ?>
  230.         <tr>
  231.                 <td colspan=14>
  232.                         <?
  233.                         echo $orders_search_query;
  234.                         ?>
  235.                 </td>
  236.         </tr>
  237.         <?
  238. }
  239.  
  240. while($data = @mysql_fetch_array($result))
  241. {
  242.         if($data['id'])
  243.         {
  244.  
  245.         if($alert && $data['alert'] <= date('Y:m:d') && $data['status'] != 3)
  246.                 $bg = 'bgcolor="'.$bgcolor[4].'"';
  247.         else
  248.                 $bg = 'bgcolor="'.$bgcolor[$data['status']].'"';
  249.  
  250.         if($deny == 1) $bg = 'bgcolor="'.$bgcolor[0].'"';
  251.         ?>
  252.         <tr>
  253.                 <td <?=$bg?> style="cursor: pointer" onclick="javascript: parent.orders_edit.location.href='?page=orders_edit&orderID=<?=$data['id']?>'">
  254.  
  255.                         <table border="0" cellpadding="0" cellspacing="0" width="100%">
  256.                         <tr>
  257.                                 <td><img src="img/1x1.gif" width="1" height="3"></td>
  258.                         </tr>
  259.                         <tr>
  260.                                 <?if($deny == 0 && $logged_user['orders'] == 3){?>
  261.                                 <td width="20" align="right"><input type="checkbox" name="orders[]" value="<?=$data['id']?>"></td>
  262.                                 <?}?>
  263.                                 <td width="5">&nbsp;</td>
  264.  
  265.                                 <td width="60"><?=$data['id']?></td>
  266.                                 <td width="10">&nbsp;</td>
  267.  
  268.                                 <td width="155"><?=$data['name']?>&nbsp;</td>
  269.                                 <td width="10">&nbsp;</td>
  270.  
  271.                                 <td width="70"><?=reverse_date($data['from'])?></td>
  272.                                 <td width="10">&nbsp;</td>
  273.  
  274.                                 <td width="70"><?=reverse_date($data['to'])?></td>
  275.                                 <td width="10">&nbsp;</td>
  276.  
  277.                                 <td width="100"><?=$data['cust']?>&nbsp;</td>
  278.                                 <td width="10" >&nbsp;</td>
  279.  
  280.                                 <td><?=$data['notes']?>&nbsp;</td>
  281.                                 <td width="5">&nbsp;</td>
  282.                         </tr>
  283.                         <tr>
  284.                                 <td><img src="img/1x1.gif" width="1" height="3"></td>
  285.                         </tr>
  286.                         </table>
  287.  
  288.                 </td>
  289.         </tr>
  290.         <tr>
  291.                 <td width="719" bgcolor="#999999"><img border="0" src="img/1x1.gif" width="1" height="1"></td>
  292.         </tr>
  293.         <?
  294.         }
  295. }
  296. ?>
  297. </table>
  298. </form>
  299.        
  300.  
  301. </body>
  302. </html>

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings