/** * reports ands logs error * * skip the log of there are filesystem problems. * * @param string $err * @param bool $skiplog */ function errDie($errstring, $skiplog = false) { $err = DATE_LOGGING . " - " . SELF . " - {$errstring}"; if (pg_ErrorMessage()) { $err .= " - " . pg_ErrorMessage(); } // log error to file die($errstring); if ($skiplog === false && ($fd = cfs::fopen("error_log", 'a'))) { if (cfs::fwrite($fd, "{$err}\n")) { $errlog_msg = "Error has been logged. Please notify the administrator."; } else { $errlog_msg = "Error writing to error log. Please notify the administrator."; } cfs::fclose($fd); } else { $errlog_msg = "Error opening error log. Please notify the administrator."; } $OUTPUT = "{$errstring} {$errlog_msg}"; require "newtemplate.php"; }
function importFile() { global $_FILES, $_POST, $psql_exec; extract($_POST); $OUTPUT = "<h3>Import Company</h3>"; $v =& new Validate(); if (!$v->isOk($compname, "string", 1, 250, "")) { return "<li class='err'>Invalid Company Name</li>" . selectFile(); } // generate code $code = "aaaa"; // make sure it 4 chars long by padding with a's $code = str_replace(" ", "", $code); $code = str_pad($code, 4, 'a', STR_PAD_RIGHT); while (1) { // check if the code exists db_con("cubit"); $rslt = db_exec("SELECT * FROM companies WHERE code='{$code}'"); // not exist! YAY!! if (pg_numrows($rslt) < 1 && !exists_compdb($code)) { break; } // increase $code[3] = chr(ord($code[3]) + 1); for ($i = 3; $i >= 0; $i--) { if (ord($code[$i]) > ord('z')) { $code[$i] = 'a'; if ($i > 0) { $code[$i - 1] = chr(ord($code[$i - 1]) + 1); } if (substr($code, 0, 3) == "zzz") { $code = "aaaa"; } } } } require_lib("progress"); displayProgress("newtemplate.php"); # Change code to lowercase $code = strtolower($code); // parse the import file if (PLATFORM == "windows") { $importfile = cfs::tempnam("cubitimport_"); } else { $importfile = cfs::tempnam("cubitimport_"); } if (!ucfs::valid("compfile")) { return "<li class='err'>" . ucfs::ferror("compfile") . "</li>"; } $fd_in = ucfs::fopen("compfile", "r"); $fd_out = cfs::fopen($importfile, "w", true); if ($fd_in === false) { return "<li class='err'>Unable to open import file.</li>"; } if ($fd_out === false) { return "<li class='err'>Unable to open temporary file required to import company.</li>"; } $company_ver = ""; while (!cfs::feof($fd_in)) { $buf = cfs::fgets($fd_in, 4096); // get the version of imported company if on this line $pos = strpos($buf, "-- V'e'r's'i'o'n:"); if ($pos !== false && $pos == 0) { $company_ver = trim(substr($buf, 17)); } // check if it valid platform $pos = strpos($buf, "-- P'l'a't'f'o'r'm:"); if ($pos !== false && $pos == 0) { $comp_platform = trim(substr($buf, 19)); if (PLATFORM != $comp_platform) { $OUTPUT .= "You cannot import another platform's company!<br>\n\t\t\t\t\tOnly from Windows to Windows or Linux to Linux.<br><Br>\n\t\t\t\t\tYour platform: " . PLATFORM . "<Br>\n\t\t\t\t\tProposed Imported Company Platform: {$comp_platform}<br>"; return $OUTPUT; } } // parse the create database code variable if on this line $pos = strpos($buf, "CREATE DATABASE"); if ($pos !== false && strpos($buf, "%c'o'd'e%") > 0) { $buf = str_replace("%c'o'd'e%", $code, $buf); } // parse the company code variable if on this line $pos = strpos($buf, "\\c "); if ($pos !== false && strpos($buf, "%c'o'd'e%") > 0) { $buf = str_replace("%c'o'd'e%", $code, $buf); } fputs($fd_out, $buf); } fclose($fd_in); fclose($fd_out); // get the version of current cubit db_con("cubit"); $cubit_ver = CUBIT_VERSION; // check if versions are the same (TEMPORARY HACK, ai tog) if ($cubit_ver != $company_ver) { return $OUTPUT . "Versions do not match:<br>\n\t\t\tProposed Imported Company version is \"{$company_ver}\"<br>\n\t\t\tYour Cubit version is \"{$cubit_ver}\"<br>\n\t\t\t<br>\n\t\t\tCheck for updates for your Cubit to support the functionality of importing non matching versions."; } // import exec("{$psql_exec}/" . PSQL_EXE . " -U postgres template1 < {$importfile}"); // insert the company db_con("cubit"); db_exec("INSERT INTO companies (code,name,ver,status) VALUES('{$code}', '{$compname}', '{$company_ver}', 'active')"); // if only one company in list, we can safely assume this was the first company // and forward to the login screen $sql = "SELECT * FROM companies"; $rslt = db_exec($sql); if (!isset($_SESSION["USER_ID"]) && $rslt && pg_num_rows($rslt) > 0) { $_SESSION["code"] = $code; $_SESSION["comp"] = $compname; $OUTPUT = "<script>top.document.location.href='doc-index.php';</script>"; return $OUTPUT; header("Location: main.php"); exit; } $OUTPUT .= "\n\tCompany has been imported successfully.<br>\n\tCompany Name: {$compname}<br>\n\tCompany Code: {$code}<br>"; return $OUTPUT; }
function translate($offset = 1) { global $_POST; extract($_POST); require_lib("validate"); $v = new validate(); $v->isOk($language, "string", 1, 2, "Invalid language code."); $v->isOk($country, "string", 2, 2, "Invalid country code."); $v->isOk($encoding, "string", 1, 255, "Invalid character encoding."); if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class=err>{$e['msg']}</li>"; } return enter($confirm); } $fields = array(); $fields["untrans"] = ""; $fields["search"] = ""; $fields["replace"] = ""; $fields["sr_inf"] = ""; extract($fields, EXTR_SKIP); if (!isset($untrans)) { $untrans = ""; } $locale = $language . "_" . $country; $sz_msgdir = "locale/{$locale}/LC_MESSAGES"; $sz_msgpath = "locale/{$locale}/LC_MESSAGES/messages.po"; // Create the directory if it does not already exist if (!cfs::is_dir($sz_msgdir)) { cfs::mkdir($sz_msgdir); } // Open the pot file if (!cfs::is_file($sz_msgpath) || cfs::filesize($sz_msgpath) == 0) { $ar_messages = cfs::get_contents("messages.po"); cfs::put_contents($sz_msgpath, $ar_messages); } // Retrieve the translation text $tl = ""; $ar_pot_file = cfs::file($sz_msgpath); if (!empty($untrans)) { $ar_pot_file = removeTranslated($ar_pot_file); } if (isset($srchrep)) { $sr_ar = searchReplace($ar_pot_file, $search, $replace, $locale); $ar_pot_file = $sr_ar["file"]; $sr_inf = "Replaced: <b>{$sr_ar['count']}</b>"; } // Retrieve the amount of msgid's for the offset $n_count = 0; for ($i = 0; $i < count($ar_pot_file); $i++) { if (!isset($ar_pot_file[$i])) { continue; } if (preg_match("/(^msgid \")([^\"]*)(\")/", $ar_pot_file[$i], $ar_matches) && $ar_matches[2] != "") { $n_count++; } } // Calculate the page numbers $current_page = intval($offset / OFFSET_SIZE) + 1; $total_pages = intval($n_count / OFFSET_SIZE) + 1; // Calculate the starting value of the next and previous buttons $n_next = $offset + OFFSET_SIZE; $n_prev = $offset - OFFSET_SIZE; // Decide which buttons to display if ($n_next > $n_count) { $sz_next = "<input type=submit value='" . ct("Translate") . "'>"; } else { $sz_next = "<input type=submit name='next' value='" . ct("Next »") . "'>"; } if ($n_prev < 0) { $sz_prev = ""; } else { $sz_prev = "<input type=submit name='prev' value='" . ct("« Previous") . "'>"; } // POT file is empty if (!count($ar_pot_file)) { $OUTPUT = "<li class='err'>Unable to load translation text.</li>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings")); return $OUTPUT; } // Start reading each line of the translation within the offset $n_count2 = 0; foreach ($ar_pot_file as $i => $value) { if (preg_match("/(^msgid \")([^\"]*)(\")/", $ar_pot_file[$i], $ar_msgid) && $ar_msgid[2] != "") { $n_count2++; if ($n_count2 >= $offset && $n_count2 < $n_next) { if (preg_match("/(^msgstr \")([^\"]*)(\")/", $ar_pot_file[$i + 1], $ar_msgstr)) { $tl .= "<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><b>" . htmlspecialchars($ar_msgid[2]) . "</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td align=center>\n\t\t\t\t\t\t<input type=text style='width: 495px;\n\t\t\t\t\t\tbackground:'" . bgcolorg() . "' name='tl[" . ($i + 1) . "]'\n\t\t\t\t\t\tvalue='{$ar_msgstr['2']}'>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; } } } } require "locale_codes.php"; // Retrieve the name of the language if (isset($ar_languages) && is_array($ar_languages)) { $lang_out = ""; foreach ($ar_languages as $lang_name => $lang_code) { if ($lang_code == $language) { $lang_out = $lang_name; } } } else { $OUTPUT = "<li class='err'>Unable to load language codes.</li>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings")); return $OUTPUT; } // Retrieve the name of the country if (isset($ar_countries) && is_array($ar_countries)) { $country_out = ""; foreach ($ar_countries as $country_name => $country_code) { if ($country_code == $country) { $country_out = $country_name; } } } else { $OUTPUT = "<li class='err'>Unable to load country codes.</li>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings")); return $OUTPUT; } $OUTPUT = "<center>\n\t<h3>" . ct("Translate Cubit") . "</h3>\n\t<form method=post action='" . SELF . "' name='form'>\n\t<input type=hidden name=key value='write'>\n\t<input type=hidden name=loffset value='{$offset}'>\n\t<input type=hidden name=language value='{$language}'>\n\t<input type=hidden name=country value='{$country}'>\n\t<input type=hidden name=encoding value='{$encoding}'>\n\t<input type='hidden' name='total_pages' value='{$total_pages}' />\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=500>\n <tr>\n <th colspan=2>" . ct("Translation Info") . "</th>\n </tr>\n\t <tr class='" . bg_class() . "'>\n\t <td>" . ct("Language") . "</td>\n\t <td>{$lang_out}</td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t <td>" . ct("Country") . "</td>\n\t <td>{$country_out}</td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t <td>" . ct("Character Encoding") . "</td>\n\t <td>\n\t {$encoding}\n\t </td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t <td>" . ct("Page") . "</td>\n\t <td>\n\t \t<input type='text' name='page_txt' size='3' value='{$current_page}'\n\t \tstyle='text-align: center'> of {$total_pages}\n\t \t<input type='submit' name='page_btn' value='Goto' />\n\t </td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td colspan='2' align='center'>\n\t \t\t<input type='checkbox' name='untrans' value='checked' {$untrans}\n\t \t\tonchange='javascript:document.form.submit();' />\n\t \t\tDisplay Only Untranslated Sentences\n\t \t</td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td colspan='2'>\n\t \t\t<table " . TMPL_tblDflts . " width='100%'>\n\t \t\t\t<tr>\n\t \t\t\t\t<th colspan='5'>Search and Replace</th>\n\t \t\t\t</tr>\n\t \t\t\t<tr class='" . bg_class() . "'>\n\t \t\t\t\t<td>Search</td>\n\t \t\t\t\t<td>\n\t \t\t\t\t\t<input type='text' name='search' value='{$search}'\n\t \t\t\t\t\tstyle='width: 100%' />\n\t \t\t\t\t</td>\n\t \t\t\t\t<td>Replace</td>\n\t \t\t\t\t<td>\n\t \t\t\t\t\t<input type='text' name='replace' value='{$replace}'\n\t \t\t\t\t\tstyle='width: 100%' />\n\t \t\t\t\t</td>\n\t \t\t\t\t<td>\n\t \t\t\t\t\t<input type='submit' name='srchrep' value='Search & Replace'\n\t \t\t\t\t\tstyle='width: 100%' />\n\t \t\t\t\t</td>\n\t \t\t\t</tr>\n\t \t\t\t<tr>\n\t \t\t\t\t<td colspan='5' align='center'>{$sr_inf}</td>\n\t \t\t\t</tr>\n\t \t\t</table>\n\t \t</td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t <td colspan=2>\n\t Some of the translation sentences includes special words and characters\n\t such as `" . htmlspecialchars("«") . "', `" . htmlspecialchars("»") . "', `<', `<<', ect... Please include these words\n\t and characters in your translation sentences as well.<p>\n\t After clicking <i>" . ct("Next") . "</i> or <i>" . ct("Previous") . "</i> the current state of the translation is automatically saved.\n\t </tr>\n\t</table>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=500>\n\t <tr>\n\t <th>" . ct("Translate") . "</th>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t <td>\n\t <table border=0 cellpadding=0 cellspacing=0 width=500>\n\t <tr class='" . bg_class() . "'>\n\t <td width=50% align=left>{$sz_prev}</td>\n\t <td width=50% align=right>{$sz_next}</td>\n\t </tr>\n\t </table>\n\t </td>\n\t </tr>\n\t {$tl}\n\t <tr class='" . bg_class() . "'>\n\t <td>\n\t <table border=0 cellpadding=0 cellspacing=0 width=500>\n\t <tr class='" . bg_class() . "'>\n\t <td width=50% align=left>{$sz_prev}</td>\n\t <td width=50% align=right>{$sz_next}</td>\n\t </tr>\n\t </table>\n\t </td>\n\t </tr>\n\t</table>\n\t</form>\n\t</center>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings")); return $OUTPUT; }
/** * reports ands logs error * * skip the log of there are filesystem problems. * * @param string $err * @param bool $skiplog */ function errDie($errstring, $skiplog = false) { pglib_transaction("ROLLBACK"); if (!defined("USER_NAME")) { define("USER_NAME", "Not Logged In"); } $err = DATE_LOGGING . " - " . SELF . " - " . USER_NAME . " - {$errstring}"; if (pg_ErrorMessage()) { $err .= " - " . pg_ErrorMessage(); } // log error to file if ($skiplog === false && ($fd = cfs::fopen("error_log", 'a'))) { if (cfs::fwrite($fd, "{$err}\n")) { $errlog_msg = "Error has been logged. Please notify the administrator."; } else { $errlog_msg = "Error writing to error log. Please notify the administrator."; } cfs::fclose($fd); } else { $errlog_msg = "Error opening error log. Please notify the administrator."; } $OUTPUT = "{$errstring} {$errlog_msg}"; require relpath("template.php"); }
/** * opens file and returns in array * * @param string $name fieldname * @return array */ static function file($name) { if (!ucfs::valid($name)) { return false; } return cfs::file($_FILES[$name]["tmp_name"], true); }