Posted by hafizan on Sun 8 Nov 01:09
report abuse | download | new post
- <?php /* IDCMS version 0.5 */
- include('Connections/localhost.php');
- include("class/class_miscellaneous.php");
- class todo {
- var $m;
- var $q;
- function create() {
- // for department have to check back reference
- $sql="
- INSERT INTO `todo` (
- `departmentId` , `department_locId` ,
- `todo_cdeId` , `assetId` ,
- `todo_tle` , `todo_des` ,
- `todo_dte` , `todo_sts` ,
- `todo_stt` , `todo_end` ,
- `todo_clr` , `staff_uniqueId`
- ) VALUES (
- '".$this->m->strict_data($_POST['departmentId'],'numeric')."',
- '".$this->m->strict_data($_POST['department_locId'],'numeric')."',
- '".$this->m->strict_data($_POST['todo_cdeId'],'numeric')."',
- '".$this->m->strict_data($_POST['assetId'],'numeric')."',
- '".$this->m->strict_data($_POST['todo_tle'],'string')."',
- '".$this->m->strict_data($_POST['todo_des'],'string')."',
- '".$this->m->strict_data($_POST['todo_dte'],'date')."',
- '".$this->m->strict_data($_POST['todo_sts'],'string')."',
- '".$this->m->strict_data($_POST['todo_stt'],'datetime')."',
- '".$this->m->strict_data($_POST['todo_end'],'datetime')."',
- '".$this->m->strict_data($_POST['todo_clr'],'datetime')."',
- '".$this->m->strict_data($_POST['staff_uniqueId'],'numeric')."');";
- $this->q->query_insert($sql);
- if($this->q->redirect=='fail') {
- $this->messageExtjs('false','Update query fail');
- } else {
- $this->messageExtjs('true','Update query Success');
- }
- }
- function read() {
- // everything given flexibility on todo
- $sql="
- SELECT *,
- `todo`.`todo_cdeId` AS `todo_cdeId`,
- `todo`.`departmentId` AS `departmentId`,
- `todo`.`department_locId` AS `department_locId`
- FROM `todo`
- LEFT JOIN `todo_cde` USING (`todo_cdeId`)
- LEFT JOIN `department` USING (`departmentId`)
- LEFT JOIN `department_loc` USING (`department_locId`)
- LEFT JOIN `asset` USING (`assetId`)
- WHERE 1";
- if($_POST['todoId']) {
- $sql.=" AND `todoId`='".$this->m->strict_data($_POST['todoId'],'numeric')."'";
- }
- $sql.=$this->searching(); // searching capibility
- // end filtering
- $this->q->query_view($sql);
- //echo $sql;
- // start json file
- $strData = NULL;
- $strData.="[";
- }
- while($row = $this->q->fetch_array()) {
- $strData.="{";
- //only sent informative information only
- if($_POST['method']=='read' && $_POST['mode']=='view') {
- // grid not required unique id
- if($row['todo_cde']) {
- $strData.="todo_cde:'".$row['todo_cde']."',";
- }
- if($row['todo_tle']) {
- $strData.="todo_tle:'".$row['todo_tle']."',";
- }
- if($row['department_nme']) {
- $strData.="department_nme:'".$row['department_nme']."',";
- }
- if($row['department_loc_name']) {
- $strData.="department_nme:'".$row['department_nme']."',";
- }
- if($row['asset_nme']) {
- $strData.="asset_nme:'".$row['asset_nme']."',";
- }
- } else if($_POST['method']=='read' && $_POST['mode']=='update') {
- // only send uniqueId if drop down
- if($row['todo_tle']) {
- $strData.="todo_tle:'".$row['todo_tle']."',";
- }
- if($row['todo_des']) {
- $strData.="todo_des:'".$row['todo_des']."',";
- }
- if($row['departmentId']) {
- $strData.="departmentId:'".$row['departmentId']."',";
- }
- if($row['department_locId']) {
- $strData.="department_locId:'".$row['department_locId']."',";
- }
- if($row['todo_cdeId']) {
- $strData.="todo_cdeId:'".$row['todo_cdeId']."',";
- }
- if($row['assetId']) {
- $strData.="assetId:'".$row['assetId']."',";
- }
- }
- // this is common can be used either grid or edit mode
- if($row['todoId']) {
- // main id
- $strData.="todoId:'".$row['todoId']."',";
- }
- if($row['todo_sts']) {
- $strData.="todo_sts:'".$row['todo_sts']."',";
- }
- if($row['todo_stt']) {
- $strData.="todo_stt:'".$row['todo_stt']."',";
- }
- if($row['todo_end']) {
- $strData.="todo_end:'".$row['todo_end']."',";
- }
- if($row['todo_clr']) {
- $strData.="todo_clr:'".$row['todo_clr']."'";
- }
- $strData.="},";
- }
- $strData= $this->q->removeComa($strData);
- $strData.="]";
- }
- $str.=$strData;
- $str.="}";
- echo $str;
- if($this->q->redirect=='fail') {
- $this->messageExtjs('false','Loading Data Error');
- }
- $this->q->free_result(); // free any resources
- }
- function chainedDepartment() {
- // everything given flexibility on todo
- $sql="
- SELECT * FROM `department_loc` WHERE 1";
- if($_POST['departmentId']) {
- $sql.=" AND `departmentId`='".$this->m->strict_data($_POST['departmentId'],'numeric')."'";
- }
- $this->q->query_view($sql);
- //echo $sql;
- // start json file
- $strData = NULL;
- $strData .= "[";
- while($row = $this->q->fetch_array()) {
- $strData.="{";
- $strData.="value:'".$row['department_locId']."',text:'".$row['department_loc_nme']."'";
- $strData.="},";
- }
- $strData= $this->q->removeComa($strData);
- $strData .="]";
- $str.=$strData;
- $str.="}";
- echo $str;
- if($this->q->redirect=='fail') {
- $this->messageExtjs('false','Loading Data Error');
- }
- $this->q->free_result(); // free any resources
- }
- function update() {
- $sql="
- UPDATE `todo`
- SET `departmentId` = '".$this->m->strict_data($_POST['departmentId'],'numeric')."',
- `department_locId` = '".$this->m->strict_data($_POST['department_locId'],'numeric')."',
- `todo_cdeId` = '".$this->m->strict_data($_POST['todo_cdeId'],'numeric')."',
- `assetId` = '".$this->m->strict_data($_POST['asset_id'],'numeric')."',
- `todo_tle` = '".$this->m->strict_data($_POST['todo_tle'],'string')."',
- `todo_des` = '".$this->m->strict_data($_POST['todo_des'],'string')."',
- `todo_dte` = '".$this->m->strict_data($_POST['todo_dte'],'date')."',
- `todo_sts` = '".$this->m->strict_data($_POST['todo_sts'],'string')."',
- `todo_stt` = '".$this->m->strict_data($_POST['todo_stt'],'datetime')."',
- `todo_end` = '".$this->m->strict_data($_POST['todo_end'],'datetime')."',
- `todo_clr` = '".$this->m->strict_data($_POST['todo_clr'],'string')."',
- `staff_uniqueId` = '".$this->m->strict_data($_POST['staff_uniqueId'],'numeric')."'
- WHERE `todoId` = '".$this->m->strict_data($_POST['todoId'],'numeric')."');";
- $this->q->query_update($sql);
- if($this->q->redirect=='fail') {
- $this->messageExtjs('false','Update query fail');
- } else {
- $this->messageExtjs('true','Update query Sucess');
- }
- }
- function delete() {
- $sql="DELETE FROM `todo` WHERE `todoId`='".$this->m->strict_data($_POST['todoId'],'numeric')."'";
- $this->q->query_update($sql);
- if($this->q->redirect=='fail') {
- $this->messageExtjs('false','Update query fail');
- } else {
- $this->messageExtjs('true','Remove query Sucess');
- }
- }
- function searching() {
- $filter=$_POST['filter']; // dereference
- for ($i=0;$i<count($filter);$i++){
- switch($filter[$i]['data']['type']){
- case 'string' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." LIKE '%".$filter[$i]['data']['value']."%'"; Break;
- case 'list' :
- $filtering=NULL;
- $fi=$filter[$i]['data']['value'];
- for ($q=0;$q<count($fi);$q++){
- $fi[$q] = "'".$fi[$q]."'";
- }
- $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." IN (".$filtering.")";
- }else{
- $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." = '".$filter[$i]['data']['value']."'";
- }
- Break;
- case 'boolean' : $qs .= " AND ".$filter[$i]['column']." = ".($filter[$i]['data']['value']); Break;
- case 'numeric' :
- switch ($filter[$i]['data']['comparison']) {
- case 'ne' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." != ".$filter[$i]['data']['value']; Break;
- case 'eq' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." = ".$filter[$i]['data']['value']; Break;
- case 'lt' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." < ".$filter[$i]['data']['value']; Break;
- case 'gt' : $qs .= " AND ".$filter[$i]['table'].".".$filter[$i]['column']." > ".$filter[$i]['data']['value']; Break;
- }
- Break;
- case 'date' :
- switch ($filter[$i]['data']['comparison']) {
- }
- Break;
- }
- }
- $where .= $qs;
- }
- return $where;
- }
- function messageExtjs($boolean,$message) {
- }
- }
- $q->limit = 5; // set as global class variable
- $q->offset = $_GET['offset']; // set as global class variable
- $q->page = $_SERVER['PHP_SELF']; // this filename
- $q->tablename = 'todo'; // tablename
- $q->rowid = 'todoId'; //rowid for delete
- $m = new miscellaneous();
- $todo_obj = new todo();
- $todo_obj->q = $q; // reference back object;
- $todo_obj->m = $m;
- // crud -create,read,update,delete
- $todo_obj->create();
- }
- if($_POST['method']=='read' && $_POST['mode']=='view') {
- $todo_obj->read();
- }
- if($_POST['method']=='read' && $_POST['mode']=='chained') {
- $todo_obj->chainedDepartment();
- }
- if($_POST['todoId'] && $_POST['method']=='save') {
- $todo_obj->update();
- }
- if($_POST['todoId'] && $_POST['method']=='delete') {
- $todo_obj->delete();
- }
- ?>
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.