/** * (non-PHPdoc) * @see class/db/IDataBase#ExecuteQuery() */ public function ExecuteQuery($query) { //echo "<br>query: $query"; DataBase::$QUERY_COUNT++; $query = str_replace("#S#", $this->_schema, $query); $result = $this->PDO->query($query); if ($result == false) { Errors::LogError("MySql:ExecuteQuery", $this->LastError() . " ::: " . $query); } return $result; }
/** * (non-PHPdoc) * @see class/db/IDataBase#ExecuteQueryWithParams() */ public function ExecuteQueryWithParams($query, $params) { $query = str_replace("#S#", $this->_schema, $query); $query = str_replace("\"", "", $query); $query = str_replace("`", "\"", $query); //echo "<br>query: $query"; $result = pg_query_params($this->_link, $query, $params); if ($result == false) { Errors::LogError("PostgreSql:ExecuteQueryWithParams", $this->LastError()); } return $result; }
/** * Import locations * @param mix $type * @return null */ public function GetLocationsAll($type = false) { if (!$this->WS()) { return null; } try { $params = array('sid' => $this->_sid); $result = $this->WS()->getSC()->__soapCall("GetLocationsAll", array($params)); $buf = $result->GetLocationsAllResult->ByteZip; $f = fopen(self::TMP_LOCATIONSALL_ZIP_FILE, "w"); fwrite($f, $buf); fclose($f); //unzip XML file with lists $zip = new ZipArchive(); if ($zip->open(self::TMP_LOCATIONSALL_ZIP_FILE)) { $fp = $zip->getStream('locationsall.xml'); if (!$fp) { exit("failed reading xml file (" . getcwd() . ")\n"); } $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 2); } fclose($fp); $zip->close(); file_put_contents(self::TMP_XML_LOCATIONSALL_FILE, $contents); if (file_exists(self::TMP_LOCATIONSALL_ZIP_FILE)) { unlink(self::TMP_LOCATIONSALL_ZIP_FILE); } $db = DataBase::GetDbInstance(); $xml = simplexml_load_file(self::TMP_XML_LOCATIONSALL_FILE); $listsNode = null; //read main nodes if ($type === false || $type == 1) { $query = "DELETE FROM powiaty"; $db->ExecuteQuery($query); foreach ($xml->Powiaty->children() as $child) { $query = "INSERT INTO powiaty VALUES(?, ?, ?)"; $params = array((int) $child['Id'], $child['Nazwa'], (int) $child['WojewodztwoId']); $r = $db->ExecuteQueryWithParams($query, $params); } } if ($type === false || $type == 2) { $query = "DELETE FROM lokalizacje"; $db->ExecuteQuery($query); foreach ($xml->Lokalizacje->children() as $child) { $query = "INSERT INTO lokalizacje VALUES(?, ?, ?, ?, ?)"; $params = array((int) $child['Id'], $child['Nazwa'], (int) $child['PowiatId'], (int) $child['WojewodztwoId'], $child['Gmina'] == 'True' ? 1 : 0); $r = $db->ExecuteQueryWithParams($query, $params); } } if ($type === false || $type == 3) { $query = "DELETE FROM dzielnice"; $db->ExecuteQuery($query); foreach ($xml->Dzielnice->children() as $child) { $query = "INSERT INTO dzielnice VALUES(?, ?, ?)"; $params = array((int) $child['Id'], $child['Nazwa'], (int) $child['LokalizacjaId']); $r = $db->ExecuteQueryWithParams($query, $params); } } if ($type === false || $type == 4) { $query = "DELETE FROM rejony"; $db->ExecuteQuery($query); foreach ($xml->Regiony->children() as $child) { $query = "INSERT INTO rejony VALUES(?, ?, ?)"; $params = array((int) $child['Id'], $child['Nazwa'], (int) $child['DzielnicaId']); $r = $db->ExecuteQueryWithParams($query, $params); } } if (file_exists(self::TMP_XML_LOCATIONSALL_FILE)) { unlink(self::TMP_XML_LOCATIONSALL_FILE); } } } catch (Exception $ex) { Errors::LogError("WebService:GetLists", $ex->getMessage()); } }
/** * Sends email. * @param string $tresc * @param string $numer * @return null */ public function SendEmail($email, $szablon) { if (!$this->WS()) { return null; } try { $params = array('sid' => $this->_sid, 'email' => $email, 'szablon' => $szablon); $result = $this->WS()->getSC()->__soapCall("SendEmail", array($params)); if ($result->SendEmailResult->Status != 0) { Errors::LogError("WebService:SendEmail", "Response: " . $result->SendEmailResult->Message); } return $result->SendEmailResult->Message; } catch (Exception $ex) { Errors::LogError("WebService:SendEmail", $ex->getMessage()); } }
/** * Clear photos from given (by id) agent or department * @param int $idusr. Agents Id. * @param int $idodd. Departments Id. * @return string */ public function ClearWebPhotos($idusr = 0, $idodd = 0) { try { $path = getcwd() . "/photos/other/"; if ($idusr > 0) { $src = $path . "3_" . $idusr . "_*.jpg"; } elseif ($idodd > 0) { $src = $path . "1_" . $idodd . "_*.jpg"; } var_dump($src); foreach (glob($src) as $filename) { unlink($filename); } } catch (Exception $ex) { Errors::LogError("VirgoAPI:ClearPhotos", $ex->getMessage()); return "ERROR"; } }
/** * Import locations * @param int $type. Type of returned locations. Acceptable values 1,2,3,4. Default false. * @return string */ public function GetLocationsAll($type = false) { try { WebServiceVirgo::WS()->LoginEx(); $ret = WebServiceVirgo::WS()->GetLocationsAll($type); WebServiceVirgo::WS()->Logout(); return $ret; } catch (Exception $ex) { Errors::LogError("VirgoAPI:GetLocationsAll", $ex->getMessage()); return "ERROR"; } }