Guest User

Untitled

a guest
Aug 22nd, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.85 KB | None | 0 0
  1. <?php
  2.     require_once('db.inc.php');
  3.     ini_set("zlib.output_compression", "On");
  4.     ini_set("zlib.outut_compression_level",6);
  5.    
  6.     // rows qty
  7.     $sql = 'SELECT id FROM repair';
  8.     try{
  9.         $s = $pdo->prepare($sql);
  10.         $s->execute();
  11.         $size = $s->rowCount();
  12.     }catch(PDOException $e){}
  13.    
  14.     if(!isset($_REQUEST['e'])){
  15.         $_REQUEST['e'] = $size;
  16.     }
  17.    
  18.     // masks
  19.     $structure['repair'] = 'id:stamp:author:custid:status:content:id01:id02:id03:id04:ptype:brand:model';
  20.        
  21.     /*
  22.     view.php?q=repair&s=0&e=5
  23.     */
  24.    
  25.     // output initialization
  26.     $output = '';
  27.        
  28.        
  29.     // prepare mask var
  30.     $mask = preg_split('@:@',$structure['repair']);
  31.  
  32.        
  33.     // context
  34.         $output .= '<h3>existing repair</h3>';
  35.         $output .= '<div class="well well-small">';
  36.         $output .= '<table class="table table-bordered">';
  37.         $output .= '<thead>';
  38.         $output .= '<tr>';
  39.         for($i = 0; $i < count($mask); $i++){
  40.             switch($mask[$i]){
  41.                 case 'id':
  42.                     $output .= '<th><i class="icon-tasks"></i>&nbsp;action(s)</th>';
  43.                 break;
  44.                 case 'stamp':
  45.                     $output .=  '<th><i class="icon-calendar"></i>&nbsp;start on</th>';
  46.                 break;
  47.                 case 'author':
  48.                     $output .=  '<th><i class="icon-user"></i>&nbsp;taken by</th>';
  49.                 break;
  50.                 case 'custid':
  51.                     $output .=  '<th><i class="icon-user"></i>&nbsp;customer</th>';
  52.                 break;
  53.                 case 'status':
  54.                     $output .=  '<th><i class="icon-tag"></i>&nbsp;status</th>';
  55.                 break;
  56.                 case 'content':
  57.                     $output .=  '<th>job description</th>';
  58.                 break;
  59.                 case 'ptype':
  60.                     $output .=  '<th>type</th>';
  61.                 break;
  62.                 default:
  63.                     $output .= '<th>'.$mask[$i].'</th>';
  64.                 break;
  65.             }
  66.         }
  67.         $output .= '</tr>';
  68.         $output .= '</thead>';
  69.         $output .= '<tbody>';
  70.        
  71.         try{
  72.             $sql = 'SELECT * FROM repair LIMIT '.$_REQUEST['s'].','.$_REQUEST['e'];
  73.         //  $sql = 'SELECT * FROM repair LIMIT :start,:end';
  74.             $s = $pdo->prepare($sql);
  75.             $s->execute();
  76.             if($s->rowCount() > 0){
  77.                 while($row = $s->fetch()){
  78.                     $data[] = array(
  79.                             'id' => $row['id'],
  80.                             'stamp' => $row['stamp'],
  81.                             'author' => $row['author'],
  82.                             'custid' => $row['custid'],
  83.                             'status' => $row['status'],
  84.                             'content' => $row['content'],
  85.                             'id01' => $row['id01'],
  86.                             'id02' => $row['id02'],
  87.                             'id03' => $row['id03'],
  88.                             'id04' => $row['id04'],
  89.                             'ptype' => $row['ptype'],
  90.                             'brand' => $row['brand'],
  91.                             'model' => $row['model']
  92.                         );
  93.                 }
  94.             }
  95.         }catch(PDOException $e){}
  96.        
  97.                 if($size > 0){
  98.                     for($i = 0; $i < count($data); $i++){
  99.                         $output .= '<tr>';
  100.                             for($e = 0; $e < count($mask); $e++){
  101.                                 switch($mask[$e]){
  102.                                     case 'id':
  103.                                         $output .= '<td>';
  104.                                         $output .= '<form action="api.php" method="post">';
  105.                                         $output .= '<input type="hidden" name="repairid" value="'.$data[$i][$mask[$e]].'">';
  106.                                         $output .= '<select name="q" class="span8">';
  107.                                         $output .= '<option value="edit-repair">edit</option>';
  108.                                         $output .= '<option value="select-repair">select</option>';
  109.                                         $output .= '<option value="delete-repair">delete</option>';
  110.                                         $output .= '<option value="view-log">view log</option>';
  111.                                         $output .= '<option value="archive-repair">archive</option>';
  112.                                         $output .= '<option value="waiting-status-repair">status:waiting</option>';
  113.                                         $output .= '<option value="order-status-repair">status:order</option>';
  114.                                         $output .= '<option value="done-status-repair">status:done</option>';
  115.                                         $output .= '<option value="called-status-repair">status:called</option>';
  116.                                         $output .= '</select>';
  117.                                         $output .= '<button type="submit" class="btn">go</button>';
  118.                                         $output .= '</form>';
  119.                                         $output .= '</td>';
  120.                                     break;
  121.                                     case 'custid':
  122.                                         $output .= '<td>';
  123.                                             /*
  124.                                                 sorting detail regarding the specific client
  125.                                             */
  126.                                             $sql = 'SELECT * FROM customer WHERE id = :id LIMIT 1';
  127.                                             try{
  128.                                                 $s = $pdo->prepare($sql);
  129.                                                 $s->bindValue(':id',$data[$i][$mask[$e]]);
  130.                                                 $s->execute();
  131.                                                 if($s->rowCount() > 0){
  132.                                                     while($row = $s->fetch()){
  133.                                                         $cust = array(
  134.                                                             'id' => $row['id'],
  135.                                                             'stamp' => $row['stamp'],
  136.                                                             'fname' => $row['fname'],
  137.                                                             'lname' => $row['lname'],
  138.                                                             'phoneHome' => $row['phoneHome'],
  139.                                                             'phoneCell' => $row['phoneCell'],
  140.                                                             'phoneWork' => $row['phoneWork'],
  141.                                                             'phoneWorkExt' => $row['phoneWorkExt'],
  142.                                                             'org' => $row['organization']
  143.                                                         );
  144.                                                     }
  145.                                                 }
  146.                                             }catch(PDOException $e){}
  147.                                            
  148.                                             if(count($cust) > 0){
  149.                                                 $output .= $cust['fname'].' '.$cust['lname'].'<br/>';
  150.                                                 $output .= '<u>phone(s)</u><br/>';
  151.                                                
  152.                                                 if($cust['phoneHome'] != '' && !(ctype_space($cust['phoneHome']))){
  153.                                                     $output .= 'home: '.$cust['phoneHome'].'<br/>';
  154.                                                 }
  155.                                                 if($cust['phoneCell'] != '' && !(ctype_space($cust['phoneCell']))){
  156.                                                     $output .= 'cell: '.$cust['phoneCell'].'<br/>';
  157.                                                 }
  158.                                                 if($cust['phoneWork'] != '' && !(ctype_space($cust['phoneWork']))){
  159.                                                     $output .= 'work: '.$cust['phoneWork'].'Ext: '.$cust['phoneWorkExt'].'<br/>';
  160.                                                 }
  161.                                                 if($cust['org'] != '' && !(ctype_space($cust['org']))){
  162.                                                     $output .= 'org: '.$cust['org'];
  163.                                                 }
  164.                                             }else{
  165.                                                 $output .= 'This client no more exists.';
  166.                                             }
  167.                                            
  168.                                         $output .= '</td>';
  169.                                     break;
  170.                                     case 'ptype':
  171.                                         $output .= '<td>';
  172.                                         switch($data[$i][$mask[$e]]){
  173.                                             case 'laptop':
  174.                                                 $output .= '<td><i class="icon-laptop icon-3x"></i><br/><b>laptop</b></td>';
  175.                                             break;
  176.                                             case 'desktop':
  177.                                                 $output .= '<td><i class="icon-desktop icon-3x"></i><br/><b>desktop</b></td>';
  178.                                             break;
  179.                                             case 'tabletpc':
  180.                                                 $output .= '<td><i class="icon-tablet icon-3x"></i><br/><b>tablet pc</b></td>';
  181.                                             break;
  182.                                             case 'cellphone':
  183.                                                 $output .= '<td><i class="icon-mobile-phone icon-3x"></i><br/><b>cellphone</b></td>';
  184.                                             break;
  185.                                             case 'other':
  186.                                                 $output .= '<td><i class="icon-gamepad icon-3x"></i><br/><b>other</b></td>';
  187.                                             break;
  188.                                         }
  189.                                         $output .= '</td>';
  190.                                     break;
  191.                                     case 'content':
  192.                                         $output .= '<td>';
  193.                                         $output .= wordwrap($data[$i][$mask[$e]],40,'<br/>');
  194.                                         $output .= '</td>';
  195.                                     break;
  196.                                     case 'status':
  197.                                         $output .= '<td>';
  198.                                         switch($data[$i][$mask[$e]]){
  199.                                             case 0:
  200.                                                 $output .= '<span class="status-not-started">not started</span>';
  201.                                             break;
  202.                                             case 1:
  203.                                                 $output .= '<span class="status-started">started</span>';
  204.                                             break;
  205.                                             case 7:
  206.                                                 $output .= '<span class="status-waiting">waiting</span>';
  207.                                             break;
  208.                                             case 8:
  209.                                                 $output .= '<span class="status-order">order</span>';
  210.                                             break;
  211.                                             case 9:
  212.                                                 $output .= '<span class="status-done">done</span>';
  213.                                             break;
  214.                                             case 10:
  215.                                                 $output .= '<span class="status-called">called</span>';
  216.                                             break;
  217.                                             default:
  218.                                                 $output .= $data[$i][$mask[$e]];
  219.                                             break;
  220.                                         }
  221.                                         $output .= '</td>';
  222.                                     break;
  223.                                     default:
  224.                                         $output .= '<td>'.$data[$i][$mask[$e]].'</td>';
  225.                                     break;
  226.                                 }
  227.                             }
  228.                         $output .= '</tr>';
  229.                     }
  230.                 }else{
  231.                     $output .= '<tr>';
  232.                     for($f = 0; $f < $data; $f++){
  233.                         $output .= '<td>no data</td>';
  234.                     }
  235.                     $output .= '</tr>';
  236.                 }
  237.        
  238.         $output .= '</tbody>';
  239.         $output .= '</table>';
  240.         $output .= '</div>';
  241.        
  242.         echo $output;
  243.  
  244. ?>
Advertisement
Add Comment
Please, Sign In to add comment