fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [9619]


From: Torstein
Subject: [Fmsystem-commits] [9619]
Date: Tue, 19 Jun 2012 07:08:36 +0000

Revision: 9619
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9619
Author:   vator
Date:     2012-06-19 07:08:36 +0000 (Tue, 19 Jun 2012)
Log Message:
-----------


Modified Paths:
--------------
    trunk/controller/inc/class.socheck_list.inc.php
    trunk/controller/inc/class.socontrol.inc.php

Modified: trunk/controller/inc/class.socheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_list.inc.php     2012-06-19 07:08:23 UTC 
(rev 9618)
+++ trunk/controller/inc/class.socheck_list.inc.php     2012-06-19 07:08:36 UTC 
(rev 9619)
@@ -118,9 +118,7 @@
                
                $counter = 0;
                $check_list = null;
-       
                while ($this->db->next_record()) {
-                       
                        if($counter == 0){
                                $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
                                
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
@@ -148,7 +146,6 @@
                                $control_item->set_type($this->db->f('type', 
true), 'string');
                                
                                
$check_item->set_control_item($control_item->toArray());
-                               
                                $check_items_array[] = $check_item->toArray();
                        }
                        
@@ -171,15 +168,13 @@
                $sql .= "WHERE cl.control_id = $control_id ";
                $sql .= "AND cl.id = ci.check_list_id "; 
                $sql .= "ORDER BY cl.id;";
-               //var_dump($sql);
+
                $this->db->query($sql);
                
                $check_list_id = 0;
                $check_list = null;
-               while ($this->db->next_record()) {
-               
+               while ($this->db->next_record()) {              
                        if( $this->db->f('cl_id', true) != $check_list_id ){
-                               
                                if($check_list_id != 0){
                                        
$check_list->set_check_item_array($check_items_array);
                                        $check_list_array[] = 
$check_list->toArray();
@@ -202,7 +197,6 @@
                        $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
                        
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
 true), 'int'));
                        
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
-                       
                        $check_items_array[] = $check_item->toArray();
                        
                        $check_list_id =  $check_list->get_id();
@@ -227,7 +221,7 @@
                $sql .= "AND NOT cl.planned_date IS NULL ";
                $sql .= "AND cl.completed_date IS NULL ";
                $sql .= "ORDER BY cl.id;";
-               //var_dump($sql);
+
                $this->db->query($sql);
                
                $check_list_id = 0;
@@ -256,7 +250,6 @@
                
                if($check_list != null){
                        $check_list_array[] = $check_list;
-               
                        return $check_list_array;
                }else {
                        return null;
@@ -278,9 +271,7 @@
                $check_list_id = 0;
                $check_list = null;
                while ($this->db->next_record()) {
-               
                        if( $this->db->f('cl_id', true) != $check_list_id ){
-                               
                                if($check_list_id != 0){
                                        $check_list_array[] = $check_list;
                                }
@@ -301,7 +292,6 @@
                
                if($check_list != null){
                        $check_list_array[] = $check_list;
-               
                        return $check_list_array;
                }else {
                        return null;
@@ -318,7 +308,7 @@
                $sql .= "AND cl.deadline < $from_date ";
                $sql .= "AND cl.completed_date IS NULL ";
                $sql .= "ORDER BY cl.id;";
-               //var_dump($sql);
+               
                $this->db->query($sql);
                
                $check_list_id = 0;
@@ -326,7 +316,6 @@
                while ($this->db->next_record()) {
                
                        if( $this->db->f('cl_id', true) != $check_list_id ){
-                               
                                if($check_list_id != 0){
                                        $check_list_array[] = $check_list;
                                }
@@ -347,14 +336,15 @@
                
                if($check_list != null){
                        $check_list_array[] = $check_list;
-               
                        return $check_list_array;
                }else {
                        return null;
                }
        }
        
-       function get_agg_check_lists_for_location( $location_code, 
$from_date_ts, $to_date_ts, $control_id = 0 ){
+       /* 
+        * TROR IKKE VI BRUKER DENNE: TORSTEIN 18.06.2012
+        function get_agg_check_lists_for_location( $location_code, 
$from_date_ts, $to_date_ts, $control_id = 0 ){
                                
                $sql =  "SELECT c.id as c_id, title, start_date, end_date, 
cl.id as cl_id, c.repeat_type, c.repeat_interval, cl.deadline, 
count(cl.num_open_cases) ";
                $sql .= "FROM controller_check_list cl, controller_control c, 
controller_check_item ci ";
@@ -385,13 +375,13 @@
                                }
                                
                                $control_array = array(
-                                                                               
"id"                            => $this->unmarshal($this->db->f('c_id', true), 
'int'),
-                                                                               
"title"                         => $this->unmarshal($this->db->f('title', 
true), 'string'),
-                                                                               
"repeat_type"           => $this->unmarshal($this->db->f('repeat_type', true), 
'int'),
-                                                                               
"repeat_interval"       => $this->unmarshal($this->db->f('repeat_interval', 
true), 'int'),
-                                                                               
"start_date"            => $this->unmarshal($this->db->f('start_date', true), 
'int'),
-                                                                               
"end_date"                      => $this->unmarshal($this->db->f('end_date', 
true), 'int')
-                                                                       );
+                                                                               
                                                "id"                            
                => $this->unmarshal($this->db->f('c_id', true), 'int'),
+                                                                               
                                                "title"                         
        => $this->unmarshal($this->db->f('title', true), 'string'),
+                                                                               
                                                "repeat_type"     => 
$this->unmarshal($this->db->f('repeat_type', true), 'int'),
+                                                                               
                                                "repeat_interval" => 
$this->unmarshal($this->db->f('repeat_interval', true), 'int'),
+                                                                               
                                                "start_date"                    
=> $this->unmarshal($this->db->f('start_date', true), 'int'),
+                                                                               
                                                "end_date"                      
        => $this->unmarshal($this->db->f('end_date', true), 'int')
+                                                                               
                                        );
                        }
 
                        $check_list_array[] = array(
@@ -411,19 +401,20 @@
                        return null;
                }       
        }
+*/ 
        
-       function get_num_open_cases_for_control( $control_id, $location_code, 
$from_date_ts, $to_date_ts, $component ){
+       function get_num_open_cases_for_control( $cl_criteria, $from_date_ts, 
$to_date_ts ){
                
                $sql =  "SELECT c.id as c_id, sum(cl.num_open_cases) as count ";
                $sql .= "FROM controller_check_list cl, controller_control c ";
-               if($component)
-               {
-                   $sql .= "WHERE cl.component_id = {$location_code} ";
+               
+               if($cl_criteria->get_component_id() > 0 && 
$cl_criteria->get_location_id() > 0){
+                   $sql .= "WHERE cl.component_id = 
{$cl_criteria->get_component_id()} ";
+                   $sql .= "AND cl.location_id = 
{$cl_criteria->get_location_id()} ";
+               }else{
+                   $sql .= "WHERE cl.location_code = 
'{$cl_criteria->get_location_code()}' ";
                }
-               else
-               {
-                   $sql .= "WHERE cl.location_code = '{$location_code}' ";
-               }
+               
                $sql .= "AND c.id = $control_id ";
                $sql .= "AND cl.control_id = c.id ";
                $sql .= "AND cl.deadline >= $from_date_ts AND $to_date_ts > 
cl.deadline ";
@@ -432,18 +423,18 @@
                $this->db->query($sql);
                
                if ($this->db->next_record() & $this->db->f('count', true) > 0) 
{
-
-                       $control_array = array(
-                                                                       "id"    
=> $this->unmarshal($this->db->f('c_id', true), 'int'),
-                                                                       "count" 
=> $this->db->f('count', true)
-                                                               );
+      $control_array = array(
+                                               "id"    => 
$this->unmarshal($this->db->f('c_id', true), 'int'),
+                                                                               
    "count" => $this->db->f('count', true)
+                                                                            );
                }
                
-               
                return $control_array;
        }
        
-       // Fetches all controls as objects with check lists 
+       
+       // Fetches all controls as objects with check lists
+       /* DET SER UT TIL AT DENNE IKKE BRUKES: TORSTEIN 18.06.2012 
        function get_check_lists_for_location( $location_code, $from_date_ts, 
$to_date_ts, $repeat_type = null, $control_id = 0 ){
                $use_location_inparam = false;
                $sql =  "SELECT c.id as c_id, title, description, start_date, 
end_date, control_area_id, c.location_code as c_location_code, repeat_type, 
repeat_interval, ";
@@ -513,6 +504,7 @@
                
                return $controls_array;
        }
+       */
        
        // Fetches control id and check lists for period and location
        function get_check_lists_for_location_2( $location_code, $from_date_ts, 
$to_date_ts, $repeat_type ){
@@ -572,6 +564,65 @@
                return $controls_array;
        }
        
+       function get_check_lists_for_component( $location_id, $component_id, 
$from_date_ts, $to_date_ts, $repeat_type ){
+               $sql =  "SELECT c.id as c_id, ";
+               $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id, cl.location_id, cl.location_code as 
cl_location_code, num_open_cases, num_pending_cases "; 
+               $sql .= "FROM controller_control c ";
+               $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = 
c.id ";
+               $sql .= "WHERE cl.location_id = $location_id ";
+               $sql .= "AND cl.component_id = $component_id ";
+               
+               if( is_numeric($repeat_type) )
+                       $sql .= "AND c.repeat_type = $repeat_type ";
+               
+               $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
+               $sql .= "ORDER BY c.id;";
+               
+               $this->db->query($sql);
+               
+               $control_id = 0;
+               $control = null;
+               $controls_array = array();
+               while ($this->db->next_record()) {
+                       
+                       if( $this->db->f('c_id', true) != $control_id ){
+                               
+                               if($control_id != 0){
+                                       
$control->set_check_lists_array($check_lists_array);
+                                       $controls_array[] = $control;
+                               }
+                       
+                               $control = new 
controller_control($this->unmarshal($this->db->f('c_id', true), 'int'));
+                                                                               
                
+                               $check_lists_array = array();
+                       }
+
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int')); 
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('component_id', 
true), 'int'));
+                       
$check_list->set_location_id($this->unmarshal($this->db->f('location_id', 
true), 'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
+                       
+                       $check_lists_array[] = $check_list;
+
+                       $control_id =  $control->get_id();
+               }
+               
+               if($control != null){
+                       $control->set_check_lists_array($check_lists_array);
+                       $controls_array[] = $control;
+               }       
+               
+               return $controls_array;
+       }
+       
        // Fetches check lists for location and control id
        function get_check_lists_for_control_and_location( $control_id, 
$location_code, $from_date_ts, $to_date_ts, $repeat_type = null ){
                $sql =  "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, completed_date, ";
@@ -606,7 +657,7 @@
                return array( "location_code" => $location_code, 
"check_lists_array" => $check_lists_array);
        }
        
-// Fetches check lists for component and control id
+       // Fetches check lists for component and control id
        function get_check_lists_for_control_and_component( $control_id, 
$component_id, $from_date_ts, $to_date_ts, $repeat_type = null ){
                $sql =  "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, completed_date, ";
                $sql .= "cl.component_id as cl_component_id, cl.location_code 
as cl_location_code, num_open_cases, num_pending_cases "; 
@@ -648,13 +699,10 @@
                $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = 
c.id ";
                $sql .= "WHERE c.id = {$control_id} "; 
                $sql .= "AND NOT planned_date IS NULL ";
-//             $sql .= "AND planned_date = {$current_date}";
-               
-//             var_dump($sql);
 
                $this->db->query($sql);
+               
                $check_lists_array = array();
-
                while ($this->db->next_record()) {
                        $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
                        $check_list->set_control_id($control_id);
@@ -670,7 +718,7 @@
                        
                        $check_lists_array[] = $check_list;
                }
-//             if()
+
                return $check_lists_array;
        }
        

Modified: trunk/controller/inc/class.socontrol.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol.inc.php        2012-06-19 07:08:23 UTC 
(rev 9618)
+++ trunk/controller/inc/class.socontrol.inc.php        2012-06-19 07:08:36 UTC 
(rev 9619)
@@ -28,14 +28,15 @@
        * @version $Id$
        */
 
-       phpgw::import_class('controller.socommon');
+  phpgw::import_class('controller.socommon');
 
-       include_class('controller', 'control', 'inc/model/');
-       include_class('controller', 'control_location', 'inc/model/');
+  include_class('controller', 'control', 'inc/model/');
+  include_class('controller', 'component', 'inc/model/');
+  include_class('controller', 'control_location', 'inc/model/');
 
-       class controller_socontrol extends controller_socommon
-       {
-               protected static $so;
+  class controller_socontrol extends controller_socommon
+  {
+    protected static $so;
 
                /**
                 * Get a static reference to the storage object associated with 
this model object
@@ -107,10 +108,6 @@
                        }else{
                                return 0;
                        }
-
-                       // Kommenterte denne ut midlertidig. 
-                       //Trenger id-en når controllen blir lagret. 
-                       //return isset($result);
                }
 
                function get_controls_for_location($location_code, $role_id, 
$from_date, $to_date, $repeat_type)
@@ -134,9 +131,9 @@
                public function get_controls_by_location($location_code, 
$from_date, $to_date, $repeat_type, $return_type = "return_object", $role_id = 
'')
                {
                        $controls_array = array();
-                       $joins .= " {$this->left_join} fm_responsibility_role 
ON (c.responsibility_id = fm_responsibility_role.id)";
                        
-                       $sql  = "SELECT distinct c.*, 
fm_responsibility_role.name AS responsibility_name FROM 
controller_control_location_list cll "; 
+                       $sql  = "SELECT distinct c.*, 
fm_responsibility_role.name AS responsibility_name "; 
+                       $sql .= "FROM controller_control_location_list cll "; 
                        $sql .= "LEFT JOIN controller_control c on 
cll.control_id=c.id ";
                        $sql .= "LEFT JOIN fm_responsibility_role ON 
fm_responsibility_role.id = c.responsibility_id ";
                        $sql .= "WHERE cll.location_code = '$location_code' ";
@@ -148,7 +145,7 @@
                        
                        $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
                        $sql .= "OR c.start_date > $from_date AND c.start_date 
< $to_date)";
-                       //var_dump($sql."<br/>");
+
                        $this->db->query($sql);
 
                        while($this->db->next_record()) {
@@ -176,18 +173,17 @@
                        if( count( $controls_array ) > 0 ){
                                return $controls_array; 
                        }
-                       else
-                       {
+                       else {
                                return null;
                        }
                }
                
-           public function 
get_controls_for_components_by_location($location_code, $from_date, $to_date, 
$repeat_type, $return_type = "return_object", $role_id = '')
+         public function 
get_controls_for_components_by_location($location_code, $from_date, $to_date, 
$repeat_type, $return_type = "return_object", $role_id = '')
                {
                        $controls_array = array();
-                       $joins .= " {$this->left_join} fm_responsibility_role 
ON (c.responsibility_id = fm_responsibility_role.id)";
                        
-                       $sql  = "SELECT distinct c.*, 
fm_responsibility_role.name AS responsibility_name FROM 
controller_control_component_list ccl "; 
+                       $sql  = "SELECT distinct c.*, 
fm_responsibility_role.name AS responsibility_name ";
+                       $sql .= "FROM controller_control_component_list ccl "; 
                        $sql .= "LEFT JOIN controller_control c on 
ccl.control_id=c.id ";
                        $sql .= "LEFT JOIN fm_responsibility_role ON 
fm_responsibility_role.id = c.responsibility_id ";
                        $sql .= "LEFT JOIN fm_bim_item ON fm_bim_item.id = 
ccl.component_id ";
@@ -200,7 +196,7 @@
                        
                        $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
                        $sql .= "OR c.end_date > $from_date AND c.start_date < 
$to_date)";
-                       //var_dump($sql."<br/>");
+
                        $this->db->query($sql);
                        
                        while($this->db->next_record()) {
@@ -227,9 +223,7 @@
 
                        if( count( $controls_array ) > 0 ){
                                return $controls_array; 
-                       }
-                       else
-                       {
+                       }else {
                                return null;
                        }
                }
@@ -238,50 +232,85 @@
                {
                        $controls_array = array();
                        
-                       $sql   = "SELECT c.id as control_id, c.*, bim_item.id, 
xpath('/beskrivelse/text()', xml_representation), bim_item.location_code, 
bim_item.address ";
+                       $sql   = "SELECT c.id as control_id, c.*, ";
+                       $sql  .= "bim_item.type as component_type, bim_item.id 
as component_id, bim_item.location_code, bim_item.address, ";
+                       $sql  .= 
"xpath('descendant-or-self::*/beskrivelse/text()', bim_item.xml_representation) 
as xml ";
                        $sql  .= "FROM controller_control_component_list cl ";
                        $sql  .= "JOIN fm_bim_item bim_item on cl.component_id 
= bim_item.id ";
                        $sql  .= "JOIN fm_bim_type bim_type on cl.location_id = 
bim_type.location_id ";
                        $sql  .= "JOIN controller_control c on cl.control_id = 
c.id ";
                        $sql  .= "AND bim_item.type = bim_type.id ";
-                       $sql  .= "AND bim_item.location_code LIKE 
'$location_code%'";
+                       $sql  .= "AND bim_item.location_code LIKE 
'$location_code%' ";
                        
                        if( $repeat_type != null){
                                $sql .= "AND c.repeat_type = $repeat_type ";
                        }
                        
                        $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
-                       $sql .= "OR c.start_date > $from_date AND c.start_date 
< $to_date)";
+                       $sql .= "OR c.start_date > $from_date AND c.start_date 
< $to_date) ";
                        
+                       $sql  .= "ORDER BY bim_item.id ";
+                        
                        $this->db->query($sql);
                        
+                       $component_id = 0;
+                       $component = null;
                        while($this->db->next_record()) {
+                               if( $this->db->f('component_id', true) != 
$component_id ){
+                                       if($component_id != 0){
+                                               
$component->set_controls_array($controls_array);
+                                               $controls_array = array();
+                                               
+                                               if($return_type == 
"return_array"){
+                                                       $components_array[] = 
$component->toArray();
+                                               }else{
+                                                       $components_array[] = 
$component;
+                                               }
+                                       }
+                                       
+                                       $component = new controller_component();
+                                       
$component->set_type($this->unmarshal($this->db->f('component_type', true), 
'int'));
+                                       
$component->set_id($this->unmarshal($this->db->f('component_id', true), 'int'));
+                                       
$component->set_guid($this->unmarshal($this->db->f('guid', true), 'string'));
+                                       
$component->set_xml($this->unmarshal($this->db->f('xml', true), 'string'));
+                                       
$component->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                                       
$component->set_loc_1($this->unmarshal($this->db->f('loc_1', true), 'string'));
+                                       
$component->set_address($this->unmarshal($this->db->f('address', true), 
'string'));
+                               }
+                               
                                $control = new 
controller_control($this->unmarshal($this->db->f('control_id', true), 'int'));
                                
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
                                
$control->set_description($this->unmarshal($this->db->f('description', true), 
'boolean'));
                                
$control->set_start_date($this->unmarshal($this->db->f('start_date', true), 
'int'));
                                
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
                                
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'int'));
+                               
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name', 
true), 'string'));
                                
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id', 
true), 'int'));
                                
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
                                
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
-                               
$control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
 true), 'string'));
                                
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
+                               
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
                                
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
-                               
$control->set_repeat_type_label($this->unmarshal($this->db->f('repeat_type', 
true), 'int'));
                                
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
                                
                                if($return_type == "return_object")
                                        $controls_array[] = $control;
                                else
                                        $controls_array[] = $control->toArray();
+                                                               
+                               $component_id = $component->get_id();
                        }
-
-                       if( count( $controls_array ) > 0 ){
-                               return $controls_array; 
-                       }
-                       else
-                       {
+                                       
+                       if($component != null){
+                               $component->set_controls_array($controls_array);
+                               
+                               if($return_type == "return_array")
+                                       $components_array[] = 
$component->toArray();
+                               else
+                                       $components_array[] = $component;
+                               
+                               return $components_array;
+                       }else {
                                return null;
                        }
                }
@@ -315,9 +344,7 @@
 
                        if( count( $controls_array ) > 0 ){
                                return $controls_array; 
-                       }
-                       else
-                       {
+                       }else {
                                return null;
                        }
                }
@@ -340,14 +367,17 @@
 
                                $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
 
-                               $controls_array[] = array("id" => $control_id, 
"title" => $title, "location_code" => $location_code, "loc1_name" => 
$location_array["loc1_name"]);
+                               $controls_array[] = array(
+                                                                               
                                                                "id" => 
$control_id, 
+                                                                               
                                                                "title" => 
$title, 
+                                                                               
                                                                "location_code" 
=> $location_code, 
+                                                                               
                                                                "loc1_name" => 
$location_array["loc1_name"]
+                                                                               
                                                        );
                        }
 
                        if( count( $controls_array ) > 0 ){
                                return $controls_array; 
-                       }
-                       else
-                       {
+                       }else {
                                return null;
                        }
                }
@@ -357,7 +387,7 @@
                        $controls_array = array();
 
                        $sql =  "SELECT c.id, c.title, ccl.component_id, 
bim_type.description, bim.location_code ";
-            $sql .= "FROM controller_control c, 
controller_control_component_list ccl, fm_bim_item bim, fm_bim_type bim_type "; 
+      $sql .= "FROM controller_control c, controller_control_component_list 
ccl, fm_bim_item bim, fm_bim_type bim_type "; 
                        $sql .= "WHERE ccl.control_id = $control_id ";
             $sql .= "AND ccl.control_id = c.id ";
                        $sql .= "AND bim.id = ccl.component_id ";
@@ -393,7 +423,10 @@
                function get_control_location($control_id, $location_code)
                {
                        $control_id = (int)$control_id;
-                       $sql =  "SELECT * FROM controller_control_location_list 
WHERE control_id = $control_id AND location_code = '$location_code'";
+                       $sql =  "SELECT * ";
+                       $sql .= "FROM controller_control_location_list ";
+                       $sql .= "WHERE control_id = $control_id ";
+                       $sql .= "AND location_code = '$location_code'";
                        
                        $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
                        
@@ -436,18 +469,26 @@
                        $this->db->transaction_begin();
                        foreach ($delete_location as $location_code)
                        {
-                               $sql =  "DELETE FROM 
controller_control_location_list  WHERE control_id = {$control_id} AND 
location_code = '{$location_code}'";
+                               $sql  = "DELETE FROM 
controller_control_location_list ";
+                               $sql .= "WHERE control_id = {$control_id} ";
+                               $sql .= "AND location_code = 
'{$location_code}'";
+                               
                                $this->db->query($sql);
                        }
 
                        foreach ($add_location as $location_code)
                        {
-                               $sql =  "SELECT * FROM 
controller_control_location_list WHERE control_id = {$control_id} AND 
location_code = '$location_code'";
+                               $sql  = "SELECT * ";
+                               $sql .= "FROM controller_control_location_list 
";
+                               $sql .= "WHERE control_id = {$control_id} ";
+                               $sql .= "AND location_code = '$location_code'";
+                               
                                $this->db->query($sql, __LINE__, __FILE__);
                        
                                if(!$this->db->next_record())
                                {
-                                       $sql =  "INSERT INTO 
controller_control_location_list (control_id, location_code) VALUES ( 
{$control_id}, '{$location_code}')";
+                                       $sql  = "INSERT INTO 
controller_control_location_list (control_id, location_code) ";
+                                       $sql .= "VALUES ( {$control_id}, 
'{$location_code}')";
                                        $this->db->query($sql);
                                }
                        }
@@ -460,7 +501,13 @@
                        $control_id             = (int) $control_id;
                        $location_id    = (int) $location_id;
                        $component_id   = (int) $component_id;
-                       $sql =  "SELECT * FROM 
controller_control_component_list WHERE control_id = {$control_id} AND 
location_id = {$location_id} AND component_id = {$component_id}";
+                       
+                       $sql  = "SELECT * ";
+                       $sql .= "FROM controller_control_component_list ";
+                       $sql .= "WHERE control_id = {$control_id} ";
+                       $sql .= "AND location_id = {$location_id} ";
+                       $sql .= "AND component_id = {$component_id}";
+                       
                        $this->db->query($sql, __LINE__, __FILE__);
                        return $this->db->next_record();
                }
@@ -491,12 +538,19 @@
                                                return false;
                                        }
 
-                                       $sql =  "SELECT * FROM 
controller_control_component_list WHERE control_id = {$control_id} AND 
location_id = {$location_id} AND component_id = {$component_id}";
+                                       $sql  = "SELECT * ";
+                                       $sql .= "FROM 
controller_control_component_list ";
+                                       $sql .= "WHERE control_id = 
{$control_id} ";
+                                       $sql .= "AND location_id = 
{$location_id} ";
+                                       $sql .= "AND component_id = 
{$component_id}";
+                                       
                                        $this->db->query($sql, __LINE__, 
__FILE__);
                        
                                        if(!$this->db->next_record())
                                        {
-                                               $sql =  "INSERT INTO 
controller_control_component_list (control_id, location_id, component_id) 
VALUES ( {$control_id}, {$location_id}, {$component_id})";
+                                               $sql =  "INSERT INTO 
controller_control_component_list (control_id, location_id, component_id) ";
+                                               $sql .= "VALUES ( 
{$control_id}, {$location_id}, {$component_id})";
+                                               
                                                $this->db->query($sql);
                                        }
                                }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]