function listLastVisit() { global $xml_database_comname; global $userfolder; global $lastvisit_config_file; $lastvisitfile = $userfolder . $lastvisit_config_file; $lastvisitfile = encode_utf8($lastvisitfile); $xml = new COM($xml_database_comname, NULL, CP_UTF8) or die("create com instance error"); $xml->ReadDB($lastvisitfile); $xml->ResetPos(); if (!$xml->FindElem("database")) { return false; } $xml->IntoElem(); if (!$xml->FindElem("lastvisit")) { return false; } $lastvisit = array(); while ($xml->FindElem("item")) { $info = array(); $xml->ResetChildPos(); while ($xml->FindChildElem("")) { $name = $xml->GetChildTagName(); $value = $xml->GetChildData(); $info[strtolower($name)] = $value; } $lastvisit[] = $info; } return true; }
function _exec($cmd) { $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run("{$cmd}", 3, false); //echo $cmd; return $oExec == 0 ? true : false; }
function actionCheckComtool() { if (class_exists('COM')) { try { $objComport = new COM("ActiveXperts.Comport"); $objComport->Logfile = "C:\\PhpSerialLog.txt"; $objComport->Device = "COM1"; $objComport->Baudrate = 9600; $objComport->ComTimeout = 1000; $objComport->Open(); print '<br>Check errros of COMport tool using (trying to connect with COM1)'; if ($objComport->LastError != 0) { if ($objComport->LastError >= 1000 && $objComport->LastError <= 1999) { print '<br>LICENSING ERROR!!!'; } else { print '<br>no licensing errors, some errors with com-port connection'; } $ErrorNum = $objComport->LastError; $ErrorDes = $objComport->GetErrorDescription($ErrorNum); echo "<br><br>Error sending commands: #{$ErrorNum} ({$ErrorDes})."; } } catch (Exception $e) { print_r($e->getMessage()); } $objComport->Close(); } else { print "Class for work with COM ports is not available"; } }
function notify($type, $title, $message) { $WshShell = new COM("WScript.Shell"); $command = 'cmd /C %cd%/exe/notifu.exe /t ' . $type . ' /p "' . $title . '" /m "' . $message . '"'; exec($command); $WshShell->Run($command, 0, false); }
/** * Get CPU frequency in MHz * * @return float * @throws phpRack_Exception If can't get cpu frequency * @see getBogoMips() * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency() */ public function getCpuFrequency() { $wmi = new COM('Winmgmts://'); $query = 'SELECT maxClockSpeed FROM CIM_Processor'; // get CPUS-s data $cpus = $wmi->execquery($query); $maxClockSpeed = 0; /** * We must iterate through all CPU-s because $cpus is object * and we can't get single entry by $cpus[0]->maxClockSpeed */ foreach ($cpus as $cpu) { $maxClockSpeed = max($maxClockSpeed, $cpu->maxClockSpeed); } /** * If returned $cpus set was empty(some error occured) * * We can't check it earlier with empty($cpus) or count($cpus) * because $cpus is object and doesn't implement countable * interface. */ if (!$maxClockSpeed) { throw new phpRack_Exception("Unable to get maxClockSpeed using COM 'Winmgmts://' and '{$query}' query"); } return floatval($maxClockSpeed); }
function pdf2swf($input, $output) { $command = "pdf2swf.exe -t \"" . $input . "\" -o \"" . $output . "\" -s flashversion=9 "; // echo $command; $Shell = new COM("WScript.shell") or die("创建COM失败"); $oExec = $Shell->exec($command); }
public static function filesize64($file) { static $iswin; if (!isset($iswin)) { $iswin = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'; } static $exec_works; if (!isset($exec_works)) { $exec_works = function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') == 'EXEC'; } // try a shell command if ($exec_works) { $cmd = $iswin ? "for %F in (\"{$file}\") do @echo %~zF" : "stat -c%s \"{$file}\""; @exec($cmd, $output); if (is_array($output) && ctype_digit($size = trim(implode("\n", $output)))) { return intval($size); } } // try the Windows COM interface if ($iswin && class_exists("COM")) { try { $fsobj = new COM('Scripting.FileSystemObject'); $f = $fsobj->GetFile(realpath($file)); $size = $f->Size; } catch (Exception $e) { $size = null; } if (ctype_digit($size)) { return intval($size); } } // if all else fails return filesize($file); }
public function syncOrg() { $obj = $this->getObj(false); $config = $this->getConfig(); $rtxParam = new COM("rtxserver.collection"); $obj->Name = "USERSYNC"; $obj->ServerIP = $config["server"]; $obj->ServerPort = $config["sdkport"]; $xmlDoc = new DOMDocument("1.0", "GB2312"); $xml = $this->makeOrgstructXml(); if ($xml) { $xmlDoc->load("userdata.xml"); $rtxParam->Add("DATA", $xmlDoc->saveXML()); $rs = $obj->Call2(1, $rtxParam); $newObj = $this->getObj(); try { $u = $newObj->UserManager(); foreach ($this->users as $user) { $u->SetUserPwd(ConvertUtil::iIconv($user, CHARSET, "gbk"), $this->pwd); } return true; } catch (Exception $exc) { $this->setError("同步过程中出现未知错误", self::ERROR_SYNC); return false; } } else { $this->setError("无法生成组织架构XML文件", self::ERROR_SYNC); return false; } }
public function filter($value) { //source: http://www.php-security.org/2010/05/09/mops-submission-04-generating-unpredictable-session-ids-and-hashes/ $entropy = ''; // try ssl first if (function_exists('openssl_random_pseudo_bytes')) { $entropy = openssl_random_pseudo_bytes(64, $strong); // skip ssl since it wasn't using the strong algo if ($strong !== true) { $entropy = ''; } } // add some basic mt_rand/uniqid combo $entropy .= uniqid(mt_rand(), true); // try to read from the windows RNG if (class_exists('COM')) { try { $com = new COM('CAPICOM.Utilities.1'); $entropy .= base64_decode($com->GetRandom(64, 0)); } catch (Exception $ex) { } } // try to read from the unix RNG if (is_readable('/dev/urandom')) { $h = fopen('/dev/urandom', 'rb'); $entropy .= fread($h, 64); fclose($h); } $hash = hash('whirlpool', $entropy); return substr($hash, 0, $this->_length); }
function RemoveDir($dir, $verbose) { if (!($dh = @opendir($dir))) { if ($verbose) { echo "can't open {$dir} \r"; } return; } else { while (false !== ($obj = readdir($dh))) { if ($obj == '.' || $obj == '..') { continue; } $newDir = $dir . '\\' . $obj; if (@unlink($newDir)) { if ($verbose) { echo "file deleted {$newDir}... \r"; } //$file_deleted++; } else { RemoveDir($newDir, $verbose); } } } $cmdline = "cmd /c rmdir {$dir}"; $WshShell = new COM("WScript.Shell"); // Make the command window but dont show it. $oExec = $WshShell->Run($cmdline, 0, false); }
function generateUniqueId($maxLength = null) { $entropy = ''; // On test ssl d'abord. if (function_exists('openssl_random_pseudo_bytes')) { $entropy = openssl_random_pseudo_bytes(64, $strong); // skip ssl since it wasn't using the strong algo if ($strong !== true) { $entropy = ''; } } // On ajoute les basics mt_rand/uniqid combo $entropy .= uniqid(mt_rand(), true); // On test la lecture de la fenêtre RNG if (class_exists('COM')) { try { $com = new COM('CAPICOM.Utilities.1'); $entropy .= base64_decode($com->GetRandom(64, 0)); } catch (Exception $ex) { } } // on test la lecture de unix RNG if (is_readable('/dev/urandom')) { $h = fopen('/dev/urandom', 'rb'); $entropy .= fread($h, 64); fclose($h); } $hash = hash('whirlpool', $entropy); if ($maxLength) { return substr($hash, 0, $maxLength); } return $hash; }
function getSize($file) { $size = filesize($file); if ($size < 0) { if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) { $size = trim(`stat -c%s {$file}`); } else { $fsobj = new COM("Scripting.FileSystemObject"); $f = $fsobj->GetFile($file); $size = $file->Size; } } if ($size > 1000000000) { $size = number_format($size / 1000000000, 2, '.', ''); $size = $size . " GB"; } else { if ($size > 1000000) { $size = number_format($size / 1000000, 2, '.', ''); $size = $size . " MB"; } else { if ($size > 4000) { $size = number_format($size / 1000, 2, '.', ''); $size = $size . " kb"; } else { $size = $size . " bytes"; } } } return $size; }
static function getListVersion($syncserver, $list) { $list[]['componentname'] = 'mysql'; $list[]['componentname'] = 'perl'; $list[]['componentname'] = 'php'; $list[]['componentname'] = 'IIS'; $list[]['componentname'] = 'Photoshop'; $list[]['componentname'] = 'InternetExplorer'; try { $obj = new COM("Winmgmts://./root/cimv2"); } catch (exception $e) { throw new lxException("com_failed", 'disk'); } $nlist = $obj->execQuery("select * from Win32_Product"); foreach ($nlist as $k => $l) { $name = $l->Name; $sing['nname'] = $name . "___" . $syncserver; $sing['componentname'] = $name; $sing['status'] = "off"; $sing['version'] = "Not Installed"; $sing['version'] = $l->Version; $sing['status'] = "on"; /* if (isOn($sing['status'])) { $sing['full_version'] = `rpm -qi $name`; } else { $sing['full_version'] = $sing['version']; } */ $ret[] = $sing; } return $ret; }
function execBg2() { $tmpBat = $this->tempBat(); $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run($tmpBat, 0, false); return $oExec == 0 ? true : false; }
static function readProcessList() { try { $obj = new COM("Winmgmts:{impersonationLevel=impersonate}!//./root/cimv2"); } catch (exception $e) { throw new lxException("com_failed", 'disk'); } try { $list = $obj->execQuery("select * from Win32_Process"); } catch (exception $e) { } $i = 0; $v = new Variant(42); foreach ($list as $l) { try { $result[$i]['nname'] = $l->ProcessId; $result[$i]['command'] = $l->Caption; $ret = $l->getOwner($v); if ($ret) { } else { $result[$i]['username'] = "******"; } $result[$i]['state'] = "ZZ"; $i++; } catch (exception $e) { $result[$i]['state'] = "ZZ"; $result[$i]['nname'] = "Error"; $result[$i]['command'] = $e->getMessage(); $result[$i]['username'] = $e->getCode(); } } return $result; }
/** * @param \RainLoop\Model\Account $oHmailAccount * @param string $sPrevPassword * @param string $sNewPassword * * @return bool */ public function ChangePassword(\RainLoop\Account $oHmailAccount, $sPrevPassword, $sNewPassword) { if ($this->oLogger) { $this->oLogger->Write('Try to change password for ' . $oHmailAccount->Email()); } $bResult = false; try { $oHmailApp = new COM("hMailServer.Application"); $oHmailApp->Connect(); if ($oHmailApp->Authenticate($this->sLogin, $this->sPassword)) { $sEmail = $oHmailAccount->Email(); $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail); $oHmailDomain = $oHmailApp->Domains->ItemByName($sDomain); if ($oHmailDomain) { $oHmailAccount = $oHmailDomain->Accounts->ItemByAddress($sEmail); if ($oHmailAccount) { $oHmailAccount->Password = $sNewPassword; $oHmailAccount->Save(); $bResult = true; } else { $this->oLogger->Write('HMAILSERVER: Unknown account (' . $sEmail . ')', \MailSo\Log\Enumerations\Type::ERROR); } } else { $this->oLogger->Write('HMAILSERVER: Unknown domain (' . $sDomain . ')', \MailSo\Log\Enumerations\Type::ERROR); } } else { $this->oLogger->Write('HMAILSERVER: Auth error', \MailSo\Log\Enumerations\Type::ERROR); } } catch (\Exception $oException) { if ($this->oLogger) { $this->oLogger->WriteException($oException); } } return $bResult; }
public static function generate($maxLength = null) { $entropy = ''; // try ssl first if (function_exists('openssl_random_pseudo_bytes')) { $entropy = openssl_random_pseudo_bytes(64, $strong); // skip ssl since it wasn't using the strong algo if ($strong !== true) { $entropy = ''; } } // add some basic mt_rand/uniqid combo $entropy .= uniqid(mt_rand(), true); // try to read from the windows RNG if (class_exists('COM')) { try { $com = new COM('CAPICOM.Utilities.1'); $entropy .= base64_decode($com->GetRandom(64, 0)); } catch (Exception $ex) { } } // try to read from the unix RNG if (is_readable('/dev/urandom')) { $h = fopen('/dev/urandom', 'rb'); $entropy .= fread($h, 64); fclose($h); } $hash = hash('whirlpool', $entropy); if ($maxLength) { return substr($hash, 0, $maxLength); } return $hash; }
private static function relocateShortcut() { $WshShell = new COM('WScript.Shell'); $desktop = $WshShell->SpecialFolders('Desktop'); $startmenu = $WshShell->SpecialFolders('Programs'); $startmenu .= DIRECTORY_SEPARATOR . 'XAMPP for Windows'; $links = array(); $links[realpath($desktop . DIRECTORY_SEPARATOR . 'XAMPP Control Panel.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'Description' => 'XAMPP Control Panel'); $links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Control Panel.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'Description' => 'XAMPP Control Panel'); $links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Setup.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_setup.bat', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_cli.exe', 'Description' => 'XAMPP Setup'); $links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Shell.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_shell.bat', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_cli.exe', 'Description' => 'XAMPP Shell'); $links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Uninstall.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'uninstall_xampp.bat', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_cli.exe', 'Description' => 'XAMPP Uninstall'); foreach ($links as $shortcut => $value) { if (is_int($shortcut)) { continue; } $oldfileperm = fileperms($shortcut); if (!chmod($shortcut, 0666) && !is_writable($shortcut)) { throw new XAMPPException('File \'' . $shortcut . '\' is not writable.'); } $ShellLink = $WshShell->CreateShortcut($shortcut); $ShellLink->TargetPath = $value['TargetPath']; $ShellLink->WorkingDirectory = $value['WorkingDirectory']; $ShellLink->WindowStyle = $value['WindowStyle']; $ShellLink->IconLocation = $value['IconLocation']; $ShellLink->Description = $value['Description']; $ShellLink->Save(); $ShellLink = null; chmod($shortcut, $oldfileperm); } $WshShell = null; return; }
static function pserverInfo() { try { $obj = new COM("Winmgmts://./root/cimv2"); } catch (exception $e) { throw new lxException("com_failed", ''); } //$list = $obj->execQuery("select TotalVisibleMemorySize, FreePhysicalMemory, FreeVirtualMemory, TotalVisibleMemorySize from Win32_OperatingSystem"); $list = $obj->execQuery("select TotalVisibleMemorySize, FreePhysicalMemory, TotalVirtualMemorySize, FreeVirtualMemory from Win32_OperatingSystem"); foreach ($list as $l) { $unit = 1024; $ret['priv_s_memory'] = $l->TotalVisibleMemorySize / $unit; $ret['used_s_memory'] = ($l->TotalVisibleMemorySize - $l->FreePhysicalMemory) / $unit; $ret['priv_s_virtual'] = $l->TotalVirtualMemorySize / $unit; $ret['used_s_virtual'] = ($l->TotalVirtualMemorySize - $l->FreeVirtualMemory) / $unit; foreach ($ret as &$vvv) { $vvv = round($vvv); } } $list = $obj->execQuery("select CurrentClockSpeed, L2CacheSize, Name from Win32_Processor"); $processornum = 0; foreach ($list as $v) { $cpu[$processornum]['used_s_cpumodel'] = $v->Name; $cpu[$processornum]['used_s_cpuspeed'] = round($v->CurrentClockSpeed / 1000, 3) . " GHz"; $cpu[$processornum]['used_s_cpucache'] = $v->L2CacheSize; $processornum++; } $ret['cpu'] = $cpu; return $ret; }
/** * fill the private content var */ public function __construct() { parent::__construct(); if (PSI_OS == 'WINNT') { $_wmi = null; // don't set this params for local connection, it will not work $strHostname = ''; $strUser = ''; $strPassword = ''; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI'); } else { $_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword); } } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data."); } if ($_wmi) { $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature')); } } }
function get_server_load() { if (stristr(PHP_OS, 'win') != false) { $fileModTime = filemtime("./load.cache"); $cache = @file_get_contents("./load.cache"); if (file_exists("./load.cache") && !empty($cache) && $fileModTime && time() - $fileModTime < 60) { $load = $cache; } else { $wmi = new COM("Winmgmts://"); $server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor"); $cpu_num = 0; $load_total = 0; foreach ($server as $cpu) { $cpu_num++; $load_total += $cpu->loadpercentage; } $load = round($load_total / $cpu_num, 2); file_put_contents("./load.cache", $load); } } else { $sys_load = sys_getloadavg(); $load = round($sys_load[0], 2); } return (int) $load; }
function zen_get_entropy($seed) { $entropy = ''; $fp = @fopen('/dev/urandom', 'rb'); if ($fp !== FALSE) { $entropy .= @fread($fp, 16); // echo "USING /dev/random" . "<br>"; @fclose($fp); } // MS-Windows platform? if (@class_exists('COM')) { // http://msdn.microsoft.com/en-us/library/aa388176(VS.85).aspx try { $CAPI_Util = new COM('CAPICOM.Utilities.1'); $entropy .= $CAPI_Util->GetRandom(16, 0); if ($entropy) { $entropy = md5($entropy, TRUE); // echo "USING WINDOWS" . "<br>"; } } catch (Exception $ex) { // echo 'Exception: ' . $ex->getMessage(); } } if (strlen($entropy) < 16) { $entropy = sha1_file('/includes/configure.php'); $entropy .= microtime() . mt_rand() . $seed; // echo "USING FALLBACK" . "<br>"; } return sha1($entropy); }
static function getServiceDetails($list) { $obj = new COM("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"); $servlist = $obj->execQuery("select * from Win32_Service"); foreach ($list as &$__l) { $__l['install_state'] = 'dull'; $__l['state'] = 'off'; $__l['boot_state'] = 'off'; } foreach ($servlist as $s) { $name = $s->Properties_("Name"); $name = strtolower($name); $name = trim($name); if (isset($list[$name])) { //dprint($s->Properties_("Name")); $__l =& $list[$name]; $__l['install_state'] = 'on'; if (trim($s->Properties_("StartMode")) === 'Auto') { $__l['boot_state'] = 'on'; } if (trim($s->Properties_("State")) === 'Running') { $__l['state'] = 'on'; } } } return $list; }
function getRandomBytes($count) { $output = ''; // we will try to obtain entropy from several sources, starting with OpenSSL if (function_exists('openssl_random_pseudo_bytes')) { $strong = FALSE; $output = openssl_random_pseudo_bytes($count, $strong); // if OpenSSL didn't use a strong cryptographic primitive, we'll find another source of entropy if (FALSE == $strong) { $output = ''; } } // if we've got a POSIX system, hopefully urandom is available if ($fd = @fopen('/dev/urandom', 'rb')) { $output = fread($fd, $count); fclose($fd); } // if we're on Windows, hopefully we can use its PRNG if (class_exists('COM')) { @($com = new COM('CAPICOM.Utilities.1')); @($output .= base64_decode($com->GetRandom($count, 0))); } // we fall back to a rather cryptographically insufficient but workable source of entropy if (strlen($output) < $count) { $output = ''; for ($i = 0; $i < $count; $i += 16) { $this->randomState = md5(microtime() . $this->randomState); $output .= md5($this->randomState, TRUE); } $output = substr($output, 0, $count); } return $output; }
/** * Windows with PHP < 5.3.0 will not have the function * openssl_random_pseudo_bytes() available, so let's use * CAPICOM to work around this deficiency. * * @param int $bytes * * @throws Exception * * @return string */ function random_bytes($bytes) { if (!is_int($bytes)) { throw new TypeError('Length must be an integer'); } if ($bytes < 1) { throw new Error('Length must be greater than 0'); } $buf = ''; $util = new COM('CAPICOM.Utilities.1'); $execCount = 0; /** * Let's not let it loop forever. If we run N times and fail to * get N bytes of random data, then CAPICOM has failed us. */ do { $buf .= base64_decode($util->GetRandom($bytes, 0)); if (RandomCompat_strlen($buf) >= $bytes) { /** * Return our random entropy buffer here: */ return RandomCompat_substr($buf, 0, $bytes); } ++$execCount; } while ($execCount < $bytes); /** * If we reach here, PHP has failed us. */ throw new Exception('PHP failed to generate random data.'); }
function on_click($widget, $event, $title, $url) { $shell = new COM('WScript.Shell'); // note 1 $shell->Run('cmd /c start "" "' . $url . '"', 0, FALSE); // note 1 unset($shell); }
function runServer() { $WshShell = new COM("WScript.Shell"); if (!file_exists('server.cmd')) { fwrite(fopen('server.cmd', 'w'), 'start C:\\xampp\\php\\php.exe ' . getcwd() . '\\server.php'); } $WshShell->Run(getcwd() . '\\server.cmd', 7, false); }
private function word2html($path) { $word = new COM("Word.Application") or die("无法打开 MS Word"); $word->visible = 1; $word->Documents->Open($path) or die("无法打开这个文件"); $htmlpath = substr($path, 0, -4); $word->ActiveDocument->SaveAs($htmlpath, 8); $word->quit(0); }
public function getFileSize($filePath) { if (!file_exists($filePath)) { throw new Exception("source file (" . $filePath . ")is not exist"); } $fs = new COM("Scripting.FileSystemObject"); $size = $fs->GetFile($filePath)->Size; return $size; }
private function print_pdf($query = "", $param = array(), $db) { if (file_exists($this->pdf_name)) { if (!unlink($this->pdf_name)) { echo "Failed to clear temp. please try again"; } } try { $ObjectFactory = new COM("CrystalRunTime.Application") or die("cannot load cr com"); $creport = $ObjectFactory->OpenReport($this->rpt_name, 1) or die("Couldn’t open report"); $ObjectFactory->LogOnServer('PDSODBC.DLL', 'mysql_' . $db, $db, 'root', 'mysql'); //$creport->RecordSelectionFormula="{company.company_name}='AL RUSHAID CONSTRUCTION CO. LTD.'"; //$creport->RecordSelectionFormula="{ogmr.job_no}='530'"; $creport->RecordSelectionFormula = $query; //$creport->RecordSelectionFormula= mysql_real_escape_string($query); $creport->EnableParameterPrompting = 0; $creport->DiscardSavedData; $creport->ReadRecords(); if (count($param) > 0) { for ($i = 1; $i <= count($param); $i++) { $field = $creport->ParameterFields($i); $end = strlen(substr($creport->ParameterFields($i)->Name, 2)) - 1; $paramName = substr($field->Name, 2, $end); $res = @$field->SetCurrentValue($param[$paramName]); if ($res != 0) { return "Failed to create report. Failed to set parameter {$i} with value " . $param[$i]; } } } $creport->ExportOptions->DiskFileName = $this->pdf_name; $creport->ExportOptions->FormatType = 31; $creport->ExportOptions->DestinationType = 1; $creport->Export(false); $crapp = null; $creport = null; $ObjectFactory = null; if (file_exists($this->pdf_name)) { echo "true"; /*$pdf = file_get_contents($this->pdf_name); if(strlen($pdf) != filesize($this->pdf_name)) return "Error: filesize=".filesize($this->pdf_name)." strlen=".strlen($pdf); header("Pragma: "); header("Cache-Control: "); header("Content-type: application/pdf"); //header("Content-Disposition: attachment;filename=" . extractName($this->rpt_name) . ".pdf"); // For IE header("Content-Disposition: attachment;filename=localhost/assets/pdf/company.pdf"); // For IE echo($pdf); exit();*/ } else { echo "Failed to export"; } } catch (Exception $e) { echo "Failed to connect to Crystal Reports 2008: {$e}"; } }