示例#1
0
" class="submit" /> 
		</div>
	</fieldset>
	
	</div>
</form>

<?php 
if (isset($_REQUEST['selected_term'])) {
    $sql_english = "SELECT * FROM " . TABLE_PREFIX . "language_text WHERE language_code='" . DEFAULT_LANGUAGE_CODE . "' AND term='" . $_REQUEST["selected_term"] . "'";
    if ($_REQUEST["term_type"] != "") {
        $sql_english .= " AND variable='" . $_REQUEST["term_type"] . "' ";
    }
    $rows_english = $dao->execute($sql_english);
    $row_english = $rows_english[0];
    $rows_selected = $languageTextDAO->getByTermAndLang($_REQUEST["selected_term"], $_REQUEST["lang_code"]);
    function trans_form()
    {
        global $row_english, $rows_selected;
        global $langs;
        global $success_error;
        global $db;
        global $addslashes;
        if (!is_array($rows_selected)) {
            // add new term
            $add_new = true;
        } else {
            $row_selected = $rows_selected[0];
            $add_new = false;
        }
        ?>
 /**
  * insert check terms into language_text and update according record in table "checks"
  * @access  private
  * @param   $checkID
  *          $term      : term to create/update into 'language_text' table
  *          $text      : text to create/update into 'language_text' table
  *          $fieldName : field name in table 'checks' to update
  * @return  true    if update successfully
  *          false   if update unsuccessful
  * @author  Cindy Qi Li
  */
 private function updateLang($checkID, $term, $text, $fieldName)
 {
     global $addslashes;
     require_once AC_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php';
     $langTextDAO = new LanguageTextDAO();
     $langs = $langTextDAO->getByTermAndLang($term, $_SESSION['lang']);
     if (is_array($langs)) {
         // term already exists. Only need to update modified text
         if ($langs[0]['text'] != $addslashes($text)) {
             $langTextDAO->setText($_SESSION['lang'], '_check', $term, $text);
         }
     } else {
         $langTextDAO->Create($_SESSION['lang'], '_check', $term, $text, '');
         $sql = "UPDATE " . TABLE_PREFIX . "checks SET " . $fieldName . "='" . $term . "' WHERE check_id=" . $checkID;
         $this->execute($sql);
     }
     return true;
 }
示例#3
0
/**
* Converts language code to actual language message, caches them according to page url
* @access	public
* @param	args				unlimited number of arguments allowed but first arg MUST be name of the language variable/term
*								i.e		$args[0] = the term to the format string $_template[term]
*										$args[1..x] = optional arguments to the formatting string 
* @return	string|array		full resulting message
* @see		$db			        in include/vitals.inc.php
* @see		cache()				in include/phpCache/phpCache.inc.php
* @see		cache_variable()	in include/phpCache/phpCache.inc.php
* @author	Joel Kronenberg
*/
function _AC()
{
    global $_cache_template, $lang_et, $_rel_url, $stripslashes;
    static $_template;
    $args = func_get_args();
    if ($args[0] == "") {
        return "";
    }
    $languageTextDAO = new LanguageTextDAO();
    // a feedback msg
    if (!is_array($args[0])) {
        /**
         * Added functionality for translating language code String (AC_ERROR|AC_INFOS|AC_WARNING|AC_FEEDBACK).*
         * to its text and returning the result. No caching needed.
         * @author Jacek Materna
         */
        // Check for specific language prefix, extendible as needed
        // 0002767:  a substring+in_array test should be faster than a preg_match test.
        // replaced the preg_match with a test of the substring.
        $sub_arg = substr($args[0], 0, 7);
        // 7 is the shortest type of msg (AC_INFO)
        if (in_array($sub_arg, array('AC_ERRO', 'AC_INFO', 'AC_WARN', 'AC_FEED', 'AC_CONF'))) {
            global $_base_path, $addslashes;
            $args[0] = $addslashes($args[0]);
            /* get $_msgs_new from the DB */
            $rows = $languageTextDAO->getMsgByTermAndLang($args[0], $_SESSION['lang']);
            $msgs = '';
            if (is_array($rows)) {
                $row = $rows[0];
                // do not cache key as a digit (no contstant(), use string)
                $msgs = str_replace('SITE_URL/', $_base_path, $row['text']);
                if (defined('AC_DEVEL') && AC_DEVEL) {
                    $msgs .= ' <small><small>(' . $args[0] . ')</small></small>';
                }
            }
            return $msgs;
        }
    }
    // a template variable
    if (!isset($_template)) {
        $url_parts = parse_url(AC_BASE_HREF);
        $name = substr($_SERVER['PHP_SELF'], strlen($url_parts['path']) - 1);
        if (!($lang_et = cache(120, 'lang', $_SESSION['lang'] . '_' . $name))) {
            /* get $_template from the DB */
            $rows = $languageTextDAO->getAllTemplateByLang($_SESSION['lang']);
            if (is_array($rows)) {
                foreach ($rows as $id => $row) {
                    //Do not overwrite the variable that existed in the cache_template already.
                    //The edited terms (_c_template) will always be at the top of the resultset
                    //0003279
                    if (isset($_cache_template[$row['term']])) {
                        continue;
                    }
                    // saves us from doing an ORDER BY
                    if ($row['language_code'] == $_SESSION['lang']) {
                        $_cache_template[$row['term']] = $stripslashes($row['text']);
                    } else {
                        if (!isset($_cache_template[$row['term']])) {
                            $_cache_template[$row['term']] = $stripslashes($row['text']);
                        }
                    }
                }
            }
            cache_variable('_cache_template');
            endcache(true, false);
        }
        $_template = $_cache_template;
    }
    $num_args = func_num_args();
    if (is_array($args[0])) {
        $args = $args[0];
        $num_args = count($args);
    }
    $format = array_shift($args);
    if (isset($_template[$format]) && count($args) > 0) {
        $outString = vsprintf($_template[$format], $args);
        $str = ob_get_contents();
    } else {
        $outString = '';
    }
    if ($outString === false) {
        return '[Error parsing language. Variable: <code>' . $format . '</code>. Language: <code>' . $_SESSION['lang'] . '</code> ]';
    }
    if (empty($outString)) {
        $rows = $languageTextDAO->getByTermAndLang($format, $_SESSION['lang']);
        if (is_array($rows) && isset($rows[0])) {
            $row = $rows[0];
            $_template[$row['term']] = $stripslashes($row['text']);
            $outString = $_template[$row['term']];
        }
        if (empty($outString)) {
            return '[ ' . $format . ' ]';
        }
    }
    return $outString;
}