0

edit1.tpl

         <tr>
            <td>Temperature Limit</td>
            <td><select id="asset_templimitv2"  type="text" class="validate[required]" div class="styledselect">
<option value="DryAC">Dry AC </option>
<option value="Chiller">Chiller </option>
<option value="Frozen">Frozen </option>
<option value="Dry">Dry</option>
       </select> </td>
      </tr>

///

<?php


class adminAssetsV2{

    function init(){
        return $this->display();
    }

    function display(){
        global $conf;
        $db = new AGDBConnection();
        $rs = new AGDBRecordset();
        $dbo = $db->init($conf['dsn']);     
        $template = new AGTemplate();
        $smarty = $template->smartyNoRewriteInit(); 
        return $smarty->fetch('forms/adminAssetsV2/jAssets.tpl');
    }   

    function executeDeletion($ajaxData){
        global $conf;   
        $f = new AGFunctionsLib();
        $db = new AGDBConnection();
        $cm = new AGDBCommand();
        $rs = new AGDBRecordset();
        $dbo = $db->init($conf['dsn']);

        $id = strip_tags($ajaxData['id']);

            $sqldel = "delete from assets where asset_ID = '$id'";

            $cm->exec($sqldel,$dbo);

            if($cm->errorMessage!=''){
                $strError .= $cm->errorMessage;     
                    echo $strError;
            }
            else{
                echo "OK";
            }
        }





    function save($ajaxData){
        global $conf;   
        $f = new AGFunctionsLib();
        $db = new AGDBConnection();
        $cm = new AGDBCommand();
        $dbo = $db->init($conf['dsn']);

        $strError = '';
            $timestamp          = date("YmdHis"); 
            $acc_ID             = $_SESSION['accountID'];
            $asset_code             = strip_tags($ajaxData['asset_code']);
            //$asset_startodometer  = strip_tags($ajaxData['asset_startodometer']);
            //$nodevice             = strip_tags($ajaxData['nodevice']);
            $nogeofence             = strip_tags($ajaxData['nogeofence']);
            $deviceID           = strip_tags($ajaxData['deviceID']);
            $geofence_ID            = strip_tags($ajaxData['geofence_ID']);
            $br_ID          = strip_tags($ajaxData['br_ID']);
            $asset_model            = strip_tags($ajaxData['asset_model']);
            $asset_name             = strip_tags($ajaxData['asset_name']);
            $asset_speedlimit       = strip_tags($ajaxData['asset_speedlimit']);
            $asset_templimitv2      = strip_tags($ajaxData['asset_templimitv2']);
            $asset_description      = strip_tags($ajaxData['asset_description']);
            $ag_ID          = strip_tags($ajaxData['ag_ID']);
            $asset_driverID         = strip_tags($ajaxData['asset_driverID']);

        if ($nogeofence==1){
        $geofence_ID=NULL;
        }
        $sql = "INSERT INTO assets (asset_datetime, asset_account_ID, asset_code, asset_geofence_ID, asset_br_ID, asset_model, asset_name, asset_speedlimit,asset_templimitv2, asset_ag_ID, asset_description, asset_type,asset_driverID)";
        $sql .=" values(NOW(), '$acc_ID', '$asset_code', '$geofence_ID','$br_ID', '$asset_model', '$asset_name','$asset_speedlimit','$asset_templimitv2','$ag_ID', '$asset_description',1,'$asset_driverID')";


        $cm->exec($sql,$dbo);
        if($cm->errorMessage!=''){
            $strError .= $cm->errorMessage;     
                echo $strError;
        }
        else
        {
                        /*if ($nodevice==1){

                        }else{
                            $sql = "update device set assetID=$asset_ID
                                where deviceID=$deviceID";      
                                $cm->exec($sql,$dbo);                               
                        }
                        */

                                echo 'OK';

        }
    }


    function addForm(){
    global $conf;
        $db = new AGDBConnection();
        $rs = new AGDBRecordset();
        $dbo = $db->init($conf['dsn']);

        $sql = "SELECT br_ID,br_name from asset_brand";
        $data = $rs->querynfetch($sql,$dbo);
        foreach ($data as $ro){
        $brand .= "<option value='".$ro['br_ID']."'>".$ro['br_name']."</option>";
        }
        $acc_filter = $_SESSION['accountID'];

        $sql = "SELECT geofence_ID,geofence_name from geofences where geofence_accountID=$acc_filter ";
        $data = $rs->querynfetch($sql,$dbo);
        $geofences .= "<option value=''></option>";
        foreach ($data as $ro){
        $geofences .= "<option value='".$ro['geofence_ID']."'>".$ro['geofence_name']."</option>";
        }
        //modem option 
        $sql = "SELECT deviceID,displayName from device where accountID=$acc_filter and (assetID = 0 or assetID is null) ";
        $data = $rs->querynfetch($sql,$dbo);
        $devices .= "<option value=''></option>";
        foreach ($data as $ro){
        $devices .= "<option value='".$ro['deviceID']."'>".$ro['displayName']."</option>";
        }

        //groups
        $sql    = "select ag_ID,ag_name from asset_group where accountID=$acc_filter";
        $data   = $rs->querynfetch($sql,$dbo);

        foreach ($data as $ro){
            $group .= "<option value='".$ro['ag_ID']."'>".$ro['ag_name']."</option>";
        }

        //driver

        $sql = "SELECT * FROM users,roles where r_ID=usr_role and r_name='Drivers' and usr_account_ID='$acc_filter'";
        $data   = $rs->querynfetch($sql,$dbo);
        $driver .= "<option value=null>none</option>";
        foreach ($data as $ro){
            $driver .= "<option value='".$ro['usr_ID']."'>".$ro['usr_realname']."</option>";
        }

        $nodevice=0;
            $template = new AGTemplate();
            $smarty = $template->smartyNoRewriteInit();
            $smarty->assign('geofences', $geofences);
            $smarty->assign('nodevice',$nodevice);
            $smarty->assign('devices', $devices);
            $smarty->assign('brand', $brand);
            $smarty->assign('driver', $driver);
            $smarty->assign('group', $group);
            $smarty->assign('tab1', $smarty->fetch('forms/adminAssetsV2/add1.tpl'));
            echo $smarty->fetch('forms/adminAssetsV2/add.tpl');



    }

    function editForm($par){
    global $conf;
        $db = new AGDBConnection();
        $rs = new AGDBRecordset();
        $dbo = $db->init($conf['dsn']);


        $id=$par['id'] ;
        $sql = "SELECT *,(select usr_realname from users where usr_ID=asset_driverID) as driver FROM assets ";
        $sql .="where  asset_ID='$id' ";
        $rows = $rs->querynfetch($sql,$dbo);

        $sql = "SELECT br_ID,br_name from asset_brand";
        $data = $rs->querynfetch($sql,$dbo);
        foreach ($data as $ro){
            if ($rows[0]['asset_br_ID']==$ro['br_ID']){
            $brand .= "<option selected value='".$ro['br_ID']."'>".$ro['br_name']."</option>";
            }else{
            $brand .= "<option value='".$ro['br_ID']."'>".$ro['br_name']."</option>";
            }
         $sql = "SELECT asset_templimitv2 from assets";
        $data = $rs->querynfetch($sql,$dbo);
        foreach ($data as $ro){
            if ($rows[0]['asset_templimitv2']==$ro['asset_templimitv2']){
            $asset_templimitv2 .= "<option selected value='".$ro['asset_templimitv2']."'>".$ro['asset_templimitv2']."</option>";
            }else{
            $asset_templimitv2 .= "<option value='".$ro['asset_templimitv2']."'>".$ro['asset_templimitv2']."</option>";
         } 
}}
        $acc_filter = $_SESSION['accountID'];

        $sql = "SELECT geofence_ID,geofence_name from geofences where geofence_accountID=$acc_filter ";
        $data = $rs->querynfetch($sql,$dbo);
        $nogeofence=1;
        $geofences .= "<option value=''></option>";
        foreach ($data as $ro){
        if ($rows[0]['asset_geofence_ID']==$ro['geofence_ID']){
                $nogeofence=0;
                $geofences .= "<option selected value='".$ro['geofence_ID']."'>".$ro['geofence_name']."</option>";
                }else{
                $geofences .= "<option value='".$ro['geofence_ID']."'>".$ro['geofence_name']."</option>";
                }
        }


        //modem option 

        /*
        $sql = "SELECT deviceID,displayName,assetID from device where (accountID=$acc_filter and (assetID = 0 or assetID is null)) or assetID=".$rows[0]['asset_ID']." ";
        $data = $rs->querynfetch($sql,$dbo);
        $nodevice=1;
        $devices .= "<option value=''></option>";
        foreach ($data as $ro){
            if ($rows[0]['asset_ID']==$ro['assetID']){
                $nodevice=0;

                $devices .= "<option selected value='".$ro['deviceID']."'>".$ro['displayName']."</option>";
                }else{
                $devices .= "<option value='".$ro['deviceID']."'>".$ro['displayName']."</option>";
                }
        }
        */

    //groups
        $sql    = "select ag_ID,ag_name from asset_group where ag_account_ID=$acc_filter";
        $data   = $rs->querynfetch($sql,$dbo);

        foreach ($data as $ro){
            if($rows[0]['asset_ag_ID']==$ro['ag_ID']){
                $group .= "<option value='".$ro['ag_ID']."' selected>".$ro['ag_name']."</option>";
            }else{
                $group .= "<option value='".$ro['ag_ID']."'>".$ro['ag_name']."</option>";

            }
        }

        //driver
        $driver .= "<option value=null>none</option>";
        if ($rows[0]['asset_driverID']<>null)
        {
            $driver .= "<option value='".$rows[0]['asset_driverID']."' selected>".$rows[0]['driver']."</option>";

        }
        $sql = "SELECT usr_ID,usr_realname FROM users,roles  where r_ID=usr_role and r_name='Drivers' and usr_account_ID='$acc_filter' and not exists (select asset_driverID from assets where  asset_driverID =usr_ID)"; 
        $data   = $rs->querynfetch($sql,$dbo);
        foreach ($data as $ro){


                $driver .= "<option value='".$ro['usr_ID']."'>".$ro['usr_realname']."</option>";

        }


            $template = new AGTemplate();
            $smarty = $template->smartyNoRewriteInit();
            $smarty->assign('geofences', $geofences);
        //  $smarty->assign('olddeviceID', $ro['deviceID']);
        //  $smarty->assign('devices', $devices);
            $smarty->assign('brand', $brand);
            $smarty->assign('asset_ID',$id);
        //  $smarty->assign('nodevice',$nodevice);
            $smarty->assign('nogeofence',$nogeofence);
            $smarty->assign('asset_code', $rows[0]['asset_code']);
            //$smarty->assign('asset_startodometer', $rows[0]['asset_startodometer']);
            $smarty->assign('asset_model', $rows[0]['asset_model']);
            $smarty->assign('asset_name', $rows[0]['asset_name']);
            $smarty->assign('asset_speedlimit', $rows[0]['asset_speedlimit']);
            $smarty->assign('asset_templimitv2',$rows[0]['asset_templimitv2']);
                     $smarty->assign('temp_calib', $rows[0]['temp_calib']);
            $smarty->assign('driver', $driver);
            $smarty->assign('group', $group);       
            $smarty->assign('asset_description', $rows[0]['asset_description']);
            $smarty->assign('tab1', $smarty->fetch('forms/adminAssetsV2/edit1.tpl'));
            echo $smarty->fetch('forms/adminAssetsV2/edit.tpl');

    }


    function getXML($ajaxData){     
        global $conf;

        $db = new AGDBConnection();
        $rs = new AGDBRecordset();
        $dbo = $db->init($conf['dsn']);


        $page = $ajaxData['page']; // get the requested page
        if($ajaxData['rows']<1){
            $limit = 10; // get how many rows we want to have into the grid
        }else{
            $limit = $ajaxData['rows'];
        }
        $sidx = $ajaxData['sidx']; // get index row - i.e. user click to sort
        $sord = $ajaxData['sord']; // get the direction
        if(!$sidx) $sidx =1;
        if(!$page) $page =1;
        $acc_filter=$_SESSION['accountID'];
    $sql = "SELECT * FROM assets,device ";
        $sql .="where  accountID='$acc_filter' and asset_ID=assetID";
        $countrows = $rs->querynfetch($sql,$dbo);


        $count =count($countrows);

        if( $count > 0 ) {
            $total_pages = ceil($count/$limit);
        } else {
            $total_pages = 0;
        }
        if ($page > $total_pages) $page=$total_pages;


        $start = $limit*$page - $limit; 

        $sql = "SELECT * ,(select br_name from asset_brand where br_ID=asset_br_ID) as br_name,(select geofence_name from geofences where geofence_ID=asset_geofence_ID) as geofence_name FROM assets,device ";
        $sql .="where  accountID='$acc_filter' and asset_ID=assetID ";
        $sql .="ORDER BY $sidx $sord LIMIT $start , $limit";

        $data = $rs->querynfetch($sql,$dbo);

        $template = new AGTemplate();
        $smartyProgress = $template->smartyInit();          

        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
        header("Cache-Control: no-cache, must-revalidate" );
        header("Pragma: no-cache" );
        header("Content-type: text/xml");
        $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
        $xml .= "<rows>";
        $xml .= "<page>$page</page>";
        $xml .= "<total>$total_pages</total>";
        $xml .= "<records>$count</records>";
        if ($data){

        foreach ($data as $ro){     
            $xml .= "<row id='$ro[asset_ID]'>";
            $xml .= "<cell>$ro[asset_ID]</cell>";
            $xml .= "<cell>$ro[asset_code]</cell>"; 
            //$xml .= "<cell>$ro[asset_startodometer]</cell>";
            $xml .= "<cell>$ro[geofence_name]</cell>";  
            $xml .= "<cell>$ro[br_name]</cell>";                            
            $xml .= "<cell>$ro[asset_model]</cell>";    
            $xml .= "<cell>$ro[asset_name]</cell>"; 
            $xml .= "<cell>$ro[asset_description]</cell>";              

            $xml .= "</row>";   
            }                                   
        }       
        $xml .= "</rows>";                                  
        echo $xml;
    }


    function update($ajaxData){
        global $conf;   
        $f = new AGFunctionsLib();
        $db = new AGDBConnection();
        $cm = new AGDBCommand();
        $dbo = $db->init($conf['dsn']);

        $strError = '';
            $timestamp              = date("YmdHis");
            $asset_ID               = strip_tags($ajaxData['asset_ID']);
            $acc_ID                 = $_SESSION['accountID'];
            $asset_code             = strip_tags($ajaxData['asset_code']);
        //  $asset_startodometer    = strip_tags($ajaxData['asset_startodometer']);
            $geofence_ID            = strip_tags($ajaxData['geofence_ID']);
    //      $deviceID               = strip_tags($ajaxData['deviceID']);
            //$olddeviceID              = strip_tags($ajaxData['olddeviceID']);
    //      $nodevice               = strip_tags($ajaxData['nodevice']);
            $nogeofence                 = strip_tags($ajaxData['nogeofence']);
            $br_ID                  = strip_tags($ajaxData['br_ID']);
            $ag_ID          = strip_tags($ajaxData['ag_ID']);
            $asset_model            =strip_tags($ajaxData['asset_model']);
            $asset_name             =strip_tags($ajaxData['asset_name']);
            $asset_description      = strip_tags($ajaxData['asset_description']);
            $asset_speedlimit       = strip_tags($ajaxData['asset_speedlimit']);
            $asset_templimitv2      = strip_tags($ajaxData['asset_templimitv2']);       
            $asset_driverID         = strip_tags($ajaxData['asset_driverID']);
                        $temp_calib                     = strip_tags($ajaxData['temp_calib']);

            if ($nogeofence==1){
                $geofence_ID=NULL;
                }   

        $sqldel = "update assets set asset_account_ID='$acc_ID',
                    asset_code='$asset_code',
                    asset_geofence_ID='$geofence_ID',
                    asset_br_ID='$br_ID',
                    asset_ag_ID='$ag_ID',
                    asset_model='$asset_model',
                    asset_name='$asset_name',
                    asset_speedlimit='$asset_speedlimit',
                    asset_templimitv2='$asset_templimitv2',
                                   temp_calib='$temp_calib',
                    asset_description='$asset_description',
                    asset_type=1 ,
                    asset_driverID='$asset_driverID'
                    where asset_ID='$asset_ID'";
                $cm->exec($sqldel,$dbo);

        if($cm->errorMessage!=''){
            $strError .= $cm->errorMessage;     
                echo $strError;
        }
        else
        {   
        /*
                                $sqldel = "update device set assetID=NULL where assetID=$asset_ID"; 
                                $cm->exec($sqldel,$dbo);

                                if ($nodevice==1){
                            //device yg assetID nya $asset_ID di ubah assetIDnya jadi 0     




                            }else{
                            $sqldel = "update device set assetID=$asset_ID
                                where deviceID=$deviceID";  
                                $cm->exec($sqldel,$dbo);                                
                            }

                    */
                    echo "OK";

        }
    }
}

?>
4

0 に答える 0