<?php
    include_once ("_dirinfo.php");
    include_once (PATH_TO_ROOT."init.php");
    include_once (PATH_TO_ROOT."config.php");
    set_time_limit(0);
    ini_set("display_errors",1);
    ini_set('error_reporting', E_ALL ^ E_NOTICE);
    
    $sql = "SELECT POST, DATE_FORMAT(DATE(Added),'%d.%m.%Y') as Added FROM Warpit_CRM._logger WHERE ChangeType = 'multiple-filed-update' AND area = 'posodabljanje_uporabnika'";
    $res = $db->SQLexecute($sql);
    echo "<pre>";
    while($row = $db->fetchAssoc($res)){
        $post = json_decode($row['POST'],true);
        if($post['action'] == "submit"){
            if(!empty($post['id_tel']))
                $data[$post['id_tel']][] = $row['Added'];
        }
    }
    
    
    foreach ($data as $key => $value) {
        $sql = "UPDATE ".WARPIT_CRM."._visitStatistic SET order_date = '".$value[0]."' WHERE id_tel = ".$key;
        $sqls[] = $sql;
        $db->SQLexecute($sql);
    }
    echo "<h1>".sizeof($sqls)."</h1>";
    print_r($sqls);
    echo "</pre>";
    
   /* $sql = "UPDATE 
                ".WARPIT_CRM."._visitStatistic as v 
            SET order_date = 
                            (SELECT 
                                    presentation_date 
                            FROM ".WARPIT_CRM."._PresentatorPermissions as p 
                            WHERE p.id_project = v.id_project
                            AND p.cati_day = v.dan
                            AND p.cati_hour = v.ura
                            AND p.cati_location = v.cati_location) WHERE order_date = '0000-00-00'";
    */
    
?>