/** * Creates a directory if it doesn't exists * @param $path */ function createDirIfNotExists($path) { if (!file_exists($path)) { printLine("Creating directory: {$path}"); mkdir($path); } }
/** * Execute an sql query in the database. The correct database connection * will be chosen and the query will be logged with the success status. * * As third parameter an alternative query can be passed, which should be * displayed instead of the executed query. This prevents leakage of * confidential information like password salts. The logfile will still * contain the executed query. * * @param $query query to execute as string * @param bool $errorProcessing true if it's an error when the query fails. * @param null $displayQuery */ function exec_query($query, $errorProcessing = true, $displayQuery = null) { global $database, $kga, $errors, $executed_queries; $conn = $database->getConnectionHandler(); $executed_queries++; $success = $conn->Query($query); Kimai_Logger::logfile($query); $err = $conn->Error(); $query = htmlspecialchars($query); $displayQuery = htmlspecialchars($displayQuery); if ($success) { $level = 'green'; } else { if ($errorProcessing) { $level = 'red'; $errors++; } else { $level = 'orange'; // something went wrong but it's not an error } } printLine($level, $displayQuery == null ? $query : $displayQuery, $err); if (!$success) { Kimai_Logger::logfile("An error has occured in query [{$query}]: " . $conn->Error()); } }
public static function getInstance() { //自らを表すインスタンスは、関数内static変数としても良い if (!isset(self::$instance)) { self::$instance = new SingletonSample(); printLine('a SingletonSample instance was created !', true); } return self::$instance; }
function outputComment(array $getComment) { printLine("Name: " . $getComment[0]); printLine("Time: " . $getComment[1]); printLine("Comment: " . $getComment[2]); // printLine($stars); echo "Name: " . $getComment[0] . '<br>'; echo "comment: " . $getComment[1] . '<br>'; echo "time: " . $getComment[2] . '<br>'; echo "**********************************" . '<br>'; }
function outputComment(array $comment1) { printLine("Name: " . $comment1[0]); printLine("Comment: " . $comment1[1]); printLine("Time: " . $comment1[2]); $stars = "***********************"; printLine($stars); echo "Name: " . $comment1[0] . '<br>'; echo "comment: " . $comment1[1] . '<br>'; echo "time: " . $comment1[2] . '<br>'; echo "****************************<br>"; }
function testExpectation($positive, $negative, $label) { try { $positive(); printLine(sprintf('"%s" positive test good', $label)); } catch (Assertion $exception) { printLine(sprintf('"%s" positive test bad', $label)); } try { $negative(); printLine(sprintf('"%s" negative test bad', $label)); } catch (Assertion $exception) { printLine(sprintf('"%s" negative test good', $label)); } }
try { $microtime = microtime(true); $mailMerge = new Zend_Service_LiveDocx_MailMerge(array('username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME, 'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD)); $mailMerge->logIn(); $duration = microtime(true) - $microtime; } catch (Zend_Service_LiveDocx_Exception $e) { $duration = -1; $errorMessage = $e->getMessage(); } if (is_null($errorMessage)) { $result = TEST_PASS; } else { $result = TEST_FAIL; $failed = true; } printLine($counter, sprintf('Logging into backend service (%01.2fs)', $duration), $result); $counter++; // ----------------------------------------------------------------------------- if (true === $failed) { $message = 'One or more tests failed. The web server environment, in which this script is running, does not meet the requirements for Zend_Service_LiveDocx_*.'; } else { $message = 'Congratulations! All tests passed. The server environment, in which this script is running, is suitable for Zend_Service_LiveDocx_*.'; } print Demos_Zend_Service_LiveDocx_Helper::wrapLine(PHP_EOL . $message . PHP_EOL . PHP_EOL); // ----------------------------------------------------------------------------- /** * Print result line * * @param $counter * @param $testString * @param $testResult
/** * Execute an sql query in the database. The correct database connection * will be chosen and the query will be logged with the success status. * * As third parameter an alternative query can be passed, which should be * displayed instead of the executed query. This prevents leakage of * confidential information like password salts. The logfile will still * contain the executed query. * * @param $query query to execute as string * @param $errorProcessing true if it's an error when the query fails. */ function exec_query($query,$errorProcessing=true,$displayQuery=null) { global $database, $kga, $errors, $executed_queries; $conn = $database->getConnectionHandler(); $executed_queries++; if ($kga['server_conn'] == "pdo") { $pdo_query = $conn->prepare($query); $success = $pdo_query->execute(array()); } else { $success = $conn->Query($query); } Logger::logfile($query); if ($kga['server_conn'] == "pdo") { $err = $pdo_query->errorInfo(); $err = serialize($err); } else { $err = $conn->Error(); } $query = htmlspecialchars($query); $displayQuery = htmlspecialchars($displayQuery); if ($success) { $level = 'green'; } else { if ($errorProcessing) { $level = 'red'; $errors++; } else { $level = 'orange'; // something went wrong but it's not an error } } printLine($level,($displayQuery==null?$query:$displayQuery),$err); if (!$success) { Logger::logfile("An error has occured in query: $query"); if ($kga['server_conn'] == "pdo") { $err = $pdo_query->errorInfo(); $err = serialize($err); } else { $err = $conn->Error(); } Logger::logfile("Error text: $err"); } }
$temp = explode('-', $temp[0]); $fixeddate = $temp[1] . "/" . $temp[2] . "/" . $temp[0]; echo "<td bgcolor={$backgrounds[$b]}>{$fixeddate}</td>"; echo "<td bgcolor={$backgrounds[$b]}>{$lastrow['6']}</td>"; echo "</tr>"; $b = ($b + 1) % 2; return $b; } $result = $sql->query($query); $curMem = -1; $firstBuy = 0; $b = 0; $lastrow = array(); while ($row = $sql->fetch_row($result)) { if ($curMem != $row[0]) { if ($curMem != -1) { $b = printLine($lastrow, $b); } $curMem = $row[0]; $firstBuy = $row[4]; } $lastrow = $row; } if (count($lastrow) > 0) { $b = printLine($lastrow, $b); } echo "</table>"; $output = ob_get_contents(); ob_end_clean(); \COREPOS\Fannie\API\data\DataCache::putFile('monthly', $output); echo $output;
$outputArray = []; for ($p = 1; $p <= yaz_hits($id); $p++) { $record = yaz_record($id, $p, "render;charset=iso5426,utf8"); //render;charset=iso5426,utf8 $error = yaz_error($id); if (!empty($error)) { echo "Error Number: " . yaz_errno($id); echo "Error Description: " . $error; echo "Additional Error Information: " . yaz_addinfo($id); } $recordArray = explode("", $record); $header = substr($recordArray[0], 0, 24); $recordContent = '<datensatz id="" typ="' . substr($header, 23, 1) . '" status="' . substr($header, 5, 1) . '" mabVersion="' . substr($header, 6, 4) . '">' . "\n"; $recordContent .= printLine(substr($recordArray[0], 24)); for ($j = 1; $j < count($recordArray); $j++) { $recordContent .= printLine($recordArray[$j]); } $recordContent .= '</datensatz>' . "\n"; $outputString .= $recordContent; array_push($outputArray, $recordContent); } $outputString .= "</datei>"; yaz_close($id); $map = $standardMabMap; if (!isset($_GET['format'])) { header('Content-type: text/xml'); echo $outputString; } else { if ($_GET['format'] == 'json') { $outputXml = simplexml_load_string($outputString); $outputMap = performMapping($map, $outputXml);
static function exportCSV($contentObjectID, $contentClassAttributeID, $languageCode) { $surveyString = ''; function printLine($list, $array) { $surveyString = ''; $found = false; foreach ($list as $key) { $login = ''; $name = ''; if (isset($array[$key]) and $key == 'user_id' and is_numeric($array[$key])) { $userID = $array[$key]; $contentObject = eZContentObject::fetch($userID); if ($contentObject instanceof eZContentObject) { $name = $contentObject->attribute('name'); $dataMap = $contentObject->attribute('data_map'); foreach ($dataMap as $contentObjectAttribute) { if ($contentObjectAttribute->attribute('data_type_string') == 'ezuser') { $user = $contentObjectAttribute->content(); if ($user instanceof eZUser) { $content = $user->attribute('login'); } } } if ($name != '') { $content .= " ({$name})"; } } $surveyString .= '"' . str_replace('"', '""', $content) . '";'; } else { if (isset($array[$key])) { $surveyString .= '"' . str_replace('"', '""', $array[$key]) . '";'; $found = true; } else { $surveyString .= '"";'; } } } if ($found === true) { $surveyString .= "\n"; } return $surveyString; } $survey = eZSurvey::fetchByObjectInfo($contentObjectID, $contentClassAttributeID, $languageCode); if (!$survey || !$survey->published()) { return false; } $questionList = $survey->fetchQuestionList(); $questions = array(); $indexList = array(); foreach (array_keys($questionList) as $key) { if ($questionList[$key]->canAnswer()) { $oldKey = $questionList[$key]->attribute('original_id'); $indexList[] = $oldKey; $questions[$oldKey] = $questionList[$key]->attribute('text'); } } $surveyINI = eZINI::instance('ezsurvey.ini'); $showHeadlineUserName = $surveyINI->variable('CSVExportSettings', 'ShowUserName') == 'true' ? true : false; if ($showHeadlineUserName === true) { $indexList[] = 'user_id'; $questions['user_id'] = $surveyINI->variable('CSVExportSettings', 'HeadlineUserName'); } $surveyString = printLine($indexList, $questions); $db = eZDB::instance(); $query = "SELECT ezsurveyquestionresult.result_id as result_id, question_id, questionoriginal_id, text, ezsurveyresult.user_id as user_id\n FROM ezsurveyquestionresult, ezsurveyresult, ezsurvey\n WHERE ezsurveyresult.id=ezsurveyquestionresult.result_id AND\n ezsurveyresult.survey_id=ezsurvey.id AND\n contentclassattribute_id='" . $contentClassAttributeID . "' AND\n contentobject_id='" . $contentObjectID . "' AND\n language_code='" . $languageCode . "'\n ORDER BY tstamp ASC, ezsurveyquestionresult.result_id ASC"; $rows = $db->arrayQuery($query); $extraQuery = "SELECT ezsurveyquestionmetadata.result_id as result_id, question_id, value\n FROM ezsurveyquestionmetadata, ezsurveyresult, ezsurvey\n WHERE ezsurveyresult.id=ezsurveyquestionmetadata.result_id AND\n ezsurveyresult.survey_id=ezsurvey.id AND\n ezsurveyquestionmetadata.value<>'' AND\n contentclassattribute_id='" . $contentClassAttributeID . "' AND\n contentobject_id='" . $contentObjectID . "' AND\n language_code='" . $languageCode . "'\n ORDER BY tstamp ASC, ezsurveyquestionmetadata.result_id ASC"; $extraResultArray = $db->arrayQuery($extraQuery); $extraResultHash = array(); foreach ($extraResultArray as $extraResultItem) { $extraResultHash[$extraResultItem['result_id']][$extraResultItem['question_id']] = $extraResultItem['value']; } $oldID = false; $answers = array(); foreach (array_keys($rows) as $key) { $row =& $rows[$key]; if ($oldID != $row['result_id']) { if ($oldID !== false) { $surveyString .= printLine($indexList, $answers); unset($answers); $answers = array(); } $oldID = $row['result_id']; } if (isset($answers[$row['questionoriginal_id']])) { $answers[$row['questionoriginal_id']] .= "; " . $row['text']; } else { $answers[$row['questionoriginal_id']] = $row['text']; } if (isset($extraResultHash[$row['result_id']][$row['question_id']])) { $answers[$row['questionoriginal_id']] .= "; " . $extraResultHash[$row['result_id']][$row['question_id']]; unset($extraResultHash[$row['result_id']][$row['question_id']]); } if (!isset($answers['user_id']) and $showHeadlineUserName === true) { $answers['user_id'] = $row['user_id']; } } if ($oldID !== false) { $surveyString .= printLine($indexList, $answers); } return $surveyString; }
function taxLine($name, $code, $qty, $amt, $tax) { return printLine(printLine(printLine(printLine($name . ':' . $code, '', 18) . ':' . $qty, '', 25) . ':' . $amt, '', 35) . ':' . $tax, ' '); }
$rsums[0] += 1; break; case '2': case '4': $reasons[1] = "1"; $rsums[1] += 1; break; case '8': $reasons[2] = "1"; $rsums[2] += 1; break; case '16': $reasons[3] = "1"; $rsums[3] += 1; break; case '32': $reasons[4] = "1"; $rsums[4] += 1; break; default: $reasons[5] = "1"; $rsums[5] += 1; } } $b = printLine($reasons, $curMem, $b); $b = printLine($rsums, 'Totals', $b); echo "</table>"; $output = ob_get_contents(); ob_end_clean(); \COREPOS\Fannie\API\data\DataCache::putFile('monthly', $output); echo $output;
/** * Imports newsletter information * */ public function importExtended() { $sOcmDb = $this->_sOcmDb; $sQ = "\r\n REPLACE INTO oxnewssubscribed \r\n (\r\n oxid,\r\n oxfname,\r\n oxlname,\r\n oxemail,\r\n oxdboptin,\r\n oxsubscribed\r\n )\r\n (\r\n SELECT \r\n mail_id,\r\n customers_firstname,\r\n customers_lastname, \r\n customers_email_address, \r\n mail_status,\r\n date_added\r\n FROM \r\n {$sOcmDb}.newsletter_recipients \r\n WHERE \r\n mail_id NOT IN (SELECT oxid FROM oxnewssubscribed)\r\n )"; $oxDB = oxDb::getDb(); $oxDB->Execute($sQ); $error = $oxDB->ErrorMsg(); if ($error) { printLine('importOrders 1 -- ' . $error); } }
function printLine($text) { echo $text . PHP_EOL; } if (isset($argv[1], $argv[2]) === false) { printLine('Invalid'); printLine('Example:'); printLine('php ./gitrip.php http://localhost:8080/.git/index ./build'); exit; } list(, $targetRepoUrl, $buildPath) = $argv; printline('Trying to get index of ' . $targetRepoUrl); $handle = fopen($targetRepoUrl, 'r'); if (is_resource($handle) === false) { printLine('Could not open index file on remote'); exit; } /** * Make build folder and init git */ if (is_dir($buildPath) === false) { mkdir($buildPath . '/.git/', 0777, true); // @todo reconsider perms } $targetIndex = $buildPath . '/.git/index'; /** * Remove any created index file */ if (file_exists($targetIndex === false)) { unlink($targetIndex);
} if ((int) $revisionDB < 1392) { Kimai_Logger::logfile("-- update to r1392"); $charset = ''; if ($kga['utf8']) { $charset = 'utf8'; } $success = write_config_file($kga['server_database'], $kga['server_hostname'], $kga['server_username'], $kga['server_password'], $charset, $kga['server_prefix'], $kga['language'], $kga['password_salt'], $kga['defaultTimezone']); if ($success) { $level = 'green'; $additional = 'charset: ' . $charset; } else { $level = 'red'; $additional = 'Unable to write config file.'; } printLine($level, 'Store charset in configuration file <i>autoconf.php</i>.', $additional); } if ((int) $revisionDB < 1393) { Kimai_Logger::logfile("-- update to r1393"); exec_query("ALTER TABLE `{$p}users` CHANGE `mail` `mail` VARCHAR(160) NULL"); exec_query("ALTER TABLE `{$p}timeSheet` CHANGE `fixedRate` `fixedRate` DECIMAL(10,2) NULL"); } // ================================================================================ // FINALIZATION: update DB version number // ================================================================================ if ((int) $revisionDB < $kga['revision'] && !$errors) { $query = sprintf("UPDATE `{$p}configuration` SET value = '%s' WHERE `option` = 'version';", $kga['version']); exec_query($query, 0); $query = sprintf("UPDATE `{$p}configuration` SET value = '%d' WHERE `option` = 'revision';", $kga['revision']); exec_query($query, 0); }