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 pastebin - collaborative debugging tool View Help


Posted by hafizan on Sun 8 Nov 01:09
report abuse | download | new post

  1. <?php   /* IDCMS version 0.5 */
  2.                 session_start();
  3.                 include('Connections/localhost.php');
  4.                 include("class/class_miscellaneous.php");
  5.        
  6.                 class todo {
  7.                         var $m;
  8.                         var $q;
  9.                         function create()                               {
  10.                                 // for department have to check back reference
  11.                                 $sql="
  12.                                 INSERT INTO `todo` (
  13.                                                         `departmentId` ,                `department_locId` ,   
  14.                                                         `todo_cdeId` ,                  `assetId` ,                            
  15.                                                         `todo_tle` ,                    `todo_des` ,                   
  16.                                                         `todo_dte` ,                    `todo_sts` ,                   
  17.                                                         `todo_stt` ,                    `todo_end` ,                   
  18.                                                         `todo_clr` ,                    `staff_uniqueId`       
  19.                                                         )       VALUES (
  20.                                                         '".$this->m->strict_data($_POST['departmentId'],'numeric')."',
  21.                                                         '".$this->m->strict_data($_POST['department_locId'],'numeric')."',
  22.                                                         '".$this->m->strict_data($_POST['todo_cdeId'],'numeric')."',
  23.                                                         '".$this->m->strict_data($_POST['assetId'],'numeric')."',
  24.                                                         '".$this->m->strict_data($_POST['todo_tle'],'string')."',
  25.                                                         '".$this->m->strict_data($_POST['todo_des'],'string')."',
  26.                                                         '".$this->m->strict_data($_POST['todo_dte'],'date')."',
  27.                                                         '".$this->m->strict_data($_POST['todo_sts'],'string')."',
  28.                                                         '".$this->m->strict_data($_POST['todo_stt'],'datetime')."',
  29.                                                         '".$this->m->strict_data($_POST['todo_end'],'datetime')."',
  30.                                                         '".$this->m->strict_data($_POST['todo_clr'],'datetime')."',
  31.                                                         '".$this->m->strict_data($_POST['staff_uniqueId'],'numeric')."');";
  32.                                 $this->q->query_insert($sql);
  33.                                 if($this->q->redirect=='fail') {
  34.                                         $this->messageExtjs('false','Update query fail');
  35.                                 } else {
  36.                                         $this->messageExtjs('true','Update query Success');
  37.                                 }
  38.                         }
  39.                         function read()                                 {
  40.                                 // everything given flexibility  on todo
  41.                                 $sql="
  42.                                 SELECT          *,
  43.                                                         `todo`.`todo_cdeId`             AS              `todo_cdeId`,
  44.                                                         `todo`.`departmentId`           AS              `departmentId`,
  45.                                                         `todo`.`department_locId`       AS              `department_locId`
  46.                                 FROM            `todo`
  47.                                 LEFT JOIN       `todo_cde`                                      USING   (`todo_cdeId`)
  48.                                 LEFT JOIN       `department`                            USING   (`departmentId`)
  49.                                 LEFT JOIN       `department_loc`                        USING   (`department_locId`)
  50.                                 LEFT JOIN       `asset`                                         USING   (`assetId`)
  51.                                 WHERE   1";
  52.                                 if($_POST['todoId']) {
  53.                                         $sql.=" AND `todoId`='".$this->m->strict_data($_POST['todoId'],'numeric')."'";
  54.                                 }
  55.                
  56.                                 $sql.=$this->searching(); // searching capibility
  57.                                 // end filtering
  58.                                 $this->q->query_view($sql);
  59.                                 //echo $sql;
  60.                                
  61.                                 // start json file
  62.                                 $str             =      trim("{");
  63.                                 $str            .=      trim("success:true,");
  64.                                 $str            .=      trim("total:'".$this->q->num_rows()."',");
  65.                                 $str            .=      trim("data:");
  66.                                 $strData         =      NULL;
  67.                                 if(empty($_POST['todoId'])) {
  68.                                                 $strData.="[";
  69.                                 }
  70.                                 while($row  =   $this->q->fetch_array()) {
  71.                                         $strData.="{";
  72.                                         //only sent informative information only
  73.                                         if($_POST['method']=='read' && $_POST['mode']=='view') {
  74.                                         // grid not required unique id
  75.                                                 if($row['todo_cde']) {
  76.                                                         $strData.="todo_cde:'".$row['todo_cde']."',";
  77.                                                 }
  78.                                                 if($row['todo_tle']) {
  79.                                                        
  80.                                                         $strData.="todo_tle:'".$row['todo_tle']."',";
  81.                                                 }
  82.                                                 if($row['department_nme']) {
  83.                                                         $strData.="department_nme:'".$row['department_nme']."',";
  84.                                                 }
  85.                                                 if($row['department_loc_name']) {
  86.                                                         $strData.="department_nme:'".$row['department_nme']."',";
  87.                                                 }
  88.                                                 if($row['asset_nme']) {
  89.                                                         $strData.="asset_nme:'".$row['asset_nme']."',";
  90.                                                 }
  91.                                         } else if($_POST['method']=='read' && $_POST['mode']=='update') {
  92.                                         // only send uniqueId if drop down
  93.                                                
  94.                                                 if($row['todo_tle']) {
  95.                                                         $strData.="todo_tle:'".$row['todo_tle']."',";
  96.                                                 }
  97.                                                 if($row['todo_des']) {
  98.                                                         $strData.="todo_des:'".$row['todo_des']."',";
  99.                                                 }
  100.                                                 if($row['departmentId']) {
  101.                                                         $strData.="departmentId:'".$row['departmentId']."',";
  102.                                                 }
  103.                                                 if($row['department_locId']) {
  104.                                                         $strData.="department_locId:'".$row['department_locId']."',";
  105.                                                 }
  106.                                                 if($row['todo_cdeId']) {
  107.                                                                
  108.                                                                 $strData.="todo_cdeId:'".$row['todo_cdeId']."',";       
  109.                                                 }
  110.                                                 if($row['assetId']) {
  111.                                                                 $strData.="assetId:'".$row['assetId']."',";
  112.                                                 }
  113.                                         }
  114.                                        
  115.                                        
  116.                                         // this is common can be used either grid or edit mode
  117.                                        
  118.                                        
  119.                                         if($row['todoId']) {
  120.                                                 // main id
  121.                                                 $strData.="todoId:'".$row['todoId']."',";
  122.                                         }
  123.                                                
  124.                                         if($row['todo_sts']) {
  125.                                                 $strData.="todo_sts:'".$row['todo_sts']."',";
  126.                                         }
  127.                                         if($row['todo_stt']) {
  128.                                                 $strData.="todo_stt:'".$row['todo_stt']."',";
  129.                                         }
  130.                                         if($row['todo_end']) {
  131.                                                 $strData.="todo_end:'".$row['todo_end']."',";
  132.                                         }
  133.                                         if($row['todo_clr']) {
  134.                                                 $strData.="todo_clr:'".$row['todo_clr']."'";
  135.                                         }
  136.                                         $strData.="},";
  137.                                 }
  138.                                  $strData= $this->q->removeComa($strData);
  139.                                 if(empty($_POST['todoId'])) {
  140.                                                 $strData.="]";
  141.                                 }
  142.                                
  143.                                 $str.=$strData;
  144.                                 $str.="}";
  145.                                 echo $str;
  146.                                 if($this->q->redirect=='fail') {
  147.                                         $this->messageExtjs('false','Loading Data Error');
  148.                                 }
  149.                                 $this->q->free_result(); // free any resources
  150.                         }
  151.                         function chainedDepartment()                            {
  152.                                 // everything given flexibility  on todo
  153.                                 $sql="
  154.                                 SELECT          *  FROM `department_loc` WHERE 1";
  155.                                 if($_POST['departmentId']) {
  156.                                         $sql.=" AND `departmentId`='".$this->m->strict_data($_POST['departmentId'],'numeric')."'";
  157.                                 }
  158.                                 $this->q->query_view($sql);
  159.                                 //echo $sql;
  160.                                
  161.                                 // start json file
  162.                                 $str             =      trim("{");
  163.                                 $str            .=      trim("success:true,");
  164.                                 $str            .=      trim("total:'".$this->q->num_rows()."',");
  165.                                
  166.                                 $strData         =      NULL;
  167.                                 $str            .=  trim("data:");
  168.                                 $strData        .= "[";
  169.                                 while($row  =   $this->q->fetch_array()) {
  170.                                         $strData.="{";
  171.                                         $strData.="value:'".$row['department_locId']."',text:'".$row['department_loc_nme']."'";
  172.                                         $strData.="},";
  173.                                 }
  174.                                  $strData= $this->q->removeComa($strData);
  175.                                 $strData        .="]";
  176.                                
  177.                                 $str.=$strData;
  178.                                 $str.="}";
  179.                                 echo $str;
  180.                                 if($this->q->redirect=='fail') {
  181.                                         $this->messageExtjs('false','Loading Data Error');
  182.                                 }
  183.                                 $this->q->free_result(); // free any resources
  184.                         }
  185.                         function update()                               {
  186.                                 $sql="         
  187.                                 UPDATE  `todo`
  188.                                 SET             `departmentId`          =       '".$this->m->strict_data($_POST['departmentId'],'numeric')."',         
  189.                                                 `department_locId`      =       '".$this->m->strict_data($_POST['department_locId'],'numeric')."',     
  190.                                                 `todo_cdeId`            =       '".$this->m->strict_data($_POST['todo_cdeId'],'numeric')."',           
  191.                                                 `assetId`                       =       '".$this->m->strict_data($_POST['asset_id'],'numeric')."',                             
  192.                                                 `todo_tle`                      =       '".$this->m->strict_data($_POST['todo_tle'],'string')."',                      
  193.                                                 `todo_des`                      =       '".$this->m->strict_data($_POST['todo_des'],'string')."',                      
  194.                                                 `todo_dte`                      =       '".$this->m->strict_data($_POST['todo_dte'],'date')."',                        
  195.                                                 `todo_sts`                      =       '".$this->m->strict_data($_POST['todo_sts'],'string')."',                      
  196.                                                 `todo_stt`                      =       '".$this->m->strict_data($_POST['todo_stt'],'datetime')."',                    
  197.                                                 `todo_end`                      =       '".$this->m->strict_data($_POST['todo_end'],'datetime')."',                    
  198.                                                 `todo_clr`                      =       '".$this->m->strict_data($_POST['todo_clr'],'string')."',                      
  199.                                                 `staff_uniqueId`        =       '".$this->m->strict_data($_POST['staff_uniqueId'],'numeric')."'
  200.                                 WHERE   `todoId`                        =       '".$this->m->strict_data($_POST['todoId'],'numeric')."');";
  201.                                 $this->q->query_update($sql);
  202.                                
  203.                                 if($this->q->redirect=='fail') {
  204.                                         $this->messageExtjs('false','Update query fail');
  205.                                 } else {
  206.                                         $this->messageExtjs('true','Update query Sucess');
  207.                                 }
  208.                                  
  209.                         }
  210.                         function delete()                               {
  211.                                 $sql="DELETE FROM `todo` WHERE `todoId`='".$this->m->strict_data($_POST['todoId'],'numeric')."'";
  212.                                 $this->q->query_update($sql);
  213.                                 if($this->q->redirect=='fail') {
  214.                                         $this->messageExtjs('false','Update query fail');
  215.                                 } else {
  216.                                         $this->messageExtjs('true','Remove query Sucess');
  217.                                 }
  218.                                  
  219.                         }
  220.                         function searching() {
  221.                                 $filter=$_POST['filter']; // dereference
  222.                                 if (is_array($filter)) {
  223.                                         for ($i=0;$i<count($filter);$i++){
  224.                                                 switch($filter[$i]['data']['type']){
  225.                                                         case 'string' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." LIKE '%".$filter[$i]['data']['value']."%'"; Break;
  226.                                                         case 'list' :
  227.                                                                 if (count($filter[$i]['data']['value'])>1){
  228.                                                                         $fi = explode(',',$filter[$i]['data']['value']);
  229.                                                                         $filtering=NULL;
  230.                                                                         $fi=$filter[$i]['data']['value'];
  231.                                                                         for ($q=0;$q<count($fi);$q++){
  232.                                                                                 $fi[$q] = "'".$fi[$q]."'";
  233.                                                                         }
  234.                                                                         $filtering=substr($filtering,0,-1);
  235.                                                                         $filter[$i]['data']['value'] = implode(',',$fi);
  236.                                                                         $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." IN (".$filtering.")";
  237.                                                                 }else{
  238.                                                                
  239.                                                                         $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." = '".$filter[$i]['data']['value']."'";
  240.                                                                 }
  241.                                                         Break;
  242.                                                         case 'boolean' : $qs .= " AND ".$filter[$i]['column']." = ".($filter[$i]['data']['value']); Break;
  243.                                                         case 'numeric' :
  244.                                                                 switch ($filter[$i]['data']['comparison']) {
  245.                                                                         case 'ne' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." != ".$filter[$i]['data']['value']; Break;
  246.                                                                         case 'eq' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." = ".$filter[$i]['data']['value']; Break;
  247.                                                                         case 'lt' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." < ".$filter[$i]['data']['value']; Break;
  248.                                                                         case 'gt' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." > ".$filter[$i]['data']['value']; Break;
  249.                                                                 }
  250.                                                         Break;
  251.                                                         case 'date' :
  252.                                                                 switch ($filter[$i]['data']['comparison']) {
  253.                                                                         case 'ne' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." != '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break;
  254.                                                                         case 'eq' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." = '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break;
  255.                                                                         case 'lt' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." < '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break;
  256.                                                                         case 'gt' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." > '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break;
  257.                                                                 }
  258.                                                         Break;
  259.                                                 }
  260.                                         }
  261.                                         $where .= $qs;
  262.                                 }
  263.                                 return $where;
  264.                         }
  265.                        
  266.                
  267.                
  268.                         function messageExtjs($boolean,$message) {
  269.                                 echo "{success: '".$boolean."', msg:'".$message."'}";
  270.                         }
  271.                 }
  272.                
  273.                 $q->limit               =       5; // set as global class variable
  274.                 $q->offset              =       $_GET['offset']; // set as global class variable
  275.                 $q->page                =       $_SERVER['PHP_SELF']; // this filename
  276.                 $q->tablename   =       'todo'; // tablename
  277.                 $q->rowid               =       'todoId'; //rowid for delete   
  278.                
  279.                 $m                              =   new miscellaneous();
  280.                 $todo_obj               =       new todo();
  281.                 $todo_obj->q    =       $q; // reference back object;
  282.                 $todo_obj->m    =       $m;
  283.                
  284.                 // crud -create,read,update,delete
  285.                 if(empty($_POST['todoId']) && $_POST['method']=='save') {
  286.                         $todo_obj->create();  
  287.                 }
  288.                 if($_POST['method']=='read' && $_POST['mode']=='view')  {
  289.                         $todo_obj->read();    
  290.                 }
  291.                 if($_POST['method']=='read' && $_POST['mode']=='chained') {
  292.                         $todo_obj->chainedDepartment();
  293.                 }
  294.                 if($_POST['todoId'] && $_POST['method']=='save')   {
  295.                         $todo_obj->update();  
  296.                 }
  297.                 if($_POST['todoId'] && $_POST['method']=='delete') {
  298.                         $todo_obj->delete();  
  299.                 }
  300.                 ?>

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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post