<?php
//ob_start();
include_once ("_dirinfo.php");
include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."config.php");
include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
require_once(PATH_TO_ROOT.'CRM/class/FirePHP.class.php');
require_once(PATH_TO_ROOT.'CRM/class/fb.php');
ini_set("display_errors",1);
/*$firephp = FirePHP::getInstance(true);
set_time_limit(0);

ini_set('error_reporting', E_ALL ^ E_NOTICE);
*/
function file_iexists($path) {
    $dirname = dirname($path);
    $filename = basename($path);
    $dir = dir($dirname);
    while ( ($file = $dir->read()) !== false) {
        if (strtolower($file) == strtolower($filename)) {
            $dir->close();
            return true;
        }
    }
    $dir->close();
    return false;
}  
$sql = "SELECT *
        FROM  ".WARPIT_CRM.".`_customerActivities`
        WHERE  `fileLocation` IS NOT NULL 
        AND fileLocation LIKE  '%?%'";
        echo file_iexists(ACTIVITE_UPLOAD_PATH."_customer_3344/PO - MARGARETA RANČIGAJ.pdf") === false ? "SHIT" : "found";
$res = $db->SQLexecute($sql);
while($row = $db->fetchAssoc($res)){
    if(file_iexists(ACTIVITE_UPLOAD_PATH.$row['fileLocation']) === false){
        echo $row['customerId']." - ".$row['fileLocation']."<br>";
    }   
}
