/**
  * Constructor.
  * 
  * Initializes availableLanguages and numLanguages.
  */
 function LanguageManager()
 {
     require_once AC_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
     $languagesDAO = new LanguagesDAO();
     // initialize available lanuguages. Available languages are the ones with status "enabled"
     $rows = $languagesDAO->getAllEnabled();
     // if there's no enabled language, set to default language and default charset
     if (!is_array($rows)) {
         $rows = array($languagesDAO->getByLangCodeAndCharset(DEFAULT_LANGUAGE_CODE, DEFAULT_CHARSET));
     }
     foreach ($rows as $i => $row) {
         $this->availableLanguages[$row['language_code']][$row['charset']] = new Language($row);
     }
     $this->numEnabledLanguages = count($this->availableLanguages);
     // initialize available lanuguages. Available languages are the ones with status "enabled"
     $rows = $languagesDAO->getAll();
     foreach ($rows as $i => $row) {
         $this->allLanguages[$row['language_code']][$row['charset']] = new Language($row);
     }
 }
Example #2
0
/************************************************************************/
/* AContent                                                             */
/************************************************************************/
/* Copyright (c) 2010                                                   */
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
include TR_INCLUDE_PATH . 'vitals.inc.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
include_once TR_INCLUDE_PATH . 'classes/Language/LanguageEditor.class.php';
$languagesDAO = new LanguagesDAO();
if (isset($_POST['id'])) {
    $pieces = explode('_', $_POST['id'], 2);
    $lang_code = $pieces[0];
}
if ((isset($_POST['delete']) || isset($_POST['export']) || isset($_POST['edit'])) && !isset($_POST['id'])) {
    $msg->addError('NO_ITEM_SELECTED');
} else {
    if ($_POST['delete']) {
        global $msg;
        if ($languageManager->getNumLanguages() == 1) {
            $msg->addError('LAST_LANGUAGE');
        }
        if (!$msg->containsErrors()) {
            header('Location: language_delete.php?id=' . $_POST['id']);
            exit;
 /**
  * Update user profile
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws InvalidParameterException
  */
 public static function apiUpdate(Request $r)
 {
     self::authenticateRequest($r);
     Validators::isStringNonEmpty($r['name'], 'name', false);
     Validators::isStringNonEmpty($r['country_id'], 'country_id', false);
     if (!is_null($r['country_id'])) {
         try {
             $r['country'] = CountriesDAO::getByPK($r['country_id']);
         } catch (Exception $e) {
             throw new InvalidDatabaseOperationException($e);
         }
     }
     if ($r['state_id'] === 'null') {
         $r['state_id'] = null;
     }
     Validators::isNumber($r['state_id'], 'state_id', false);
     if (!is_null($r['state_id'])) {
         try {
             $r['state'] = StatesDAO::getByPK($r['state_id']);
         } catch (Exception $e) {
             throw new InvalidDatabaseOperationException($e);
         }
     }
     if (!is_null($r['school_id'])) {
         if (is_numeric($r['school_id'])) {
             try {
                 $r['school'] = SchoolsDAO::getByPK($r['school_id']);
             } catch (Exception $e) {
                 throw new InvalidDatabaseOperationException($e);
             }
             if (is_null($r['school'])) {
                 throw new InvalidParameterException('parameterInvalid', 'school');
             }
         } elseif (empty($r['school_name'])) {
             $r['school_id'] = null;
         } else {
             try {
                 $schoolR = new Request(array('name' => $r['school_name'], 'state_id' => $r['state_id'], 'auth_token' => $r['auth_token']));
                 $response = SchoolController::apiCreate($schoolR);
                 $r['school_id'] = $response['school_id'];
             } catch (Exception $e) {
                 throw new InvalidDatabaseOperationException($e);
             }
         }
     }
     Validators::isStringNonEmpty($r['scholar_degree'], 'scholar_degree', false);
     if (!is_null($r['graduation_date'])) {
         if (is_numeric($r['graduation_date'])) {
             $r['graduation_date'] = (int) $r['graduation_date'];
         } else {
             Validators::isDate($r['graduation_date'], 'graduation_date', false);
             $r['graduation_date'] = strtotime($r['graduation_date']);
         }
     }
     if (!is_null($r['birth_date'])) {
         if (is_numeric($r['birth_date'])) {
             $r['birth_date'] = (int) $r['birth_date'];
         } else {
             Validators::isDate($r['birth_date'], 'birth_date', false);
             $r['birth_date'] = strtotime($r['birth_date']);
         }
     }
     if (!is_null($r['locale'])) {
         // find language in Language
         $query = LanguagesDAO::search(new Languages(array('name' => $r['locale'])));
         if (sizeof($query) == 1) {
             $r['current_user']->setLanguageId($query[0]->getLanguageId());
         }
     }
     $valueProperties = array('name', 'country_id', 'state_id', 'scholar_degree', 'school_id', 'graduation_date' => array('transform' => function ($value) {
         return gmdate('Y-m-d', $value);
     }), 'birth_date' => array('transform' => function ($value) {
         return gmdate('Y-m-d', $value);
     }));
     self::updateValueProperties($r, $r['current_user'], $valueProperties);
     try {
         UsersDAO::save($r['current_user']);
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     }
     // Expire profile cache
     Cache::deleteFromCache(Cache::USER_PROFILE, $r['current_user']->getUsername());
     $sessionController = new SessionController();
     $sessionController->InvalidateCache();
     return array('status' => 'ok');
 }
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
// $Id$
define('AC_INCLUDE_PATH', '../include/');
include AC_INCLUDE_PATH . 'vitals.inc.php';
include_once AC_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
include_once AC_INCLUDE_PATH . 'classes/DAO/LangCodesDAO.class.php';
include_once AC_INCLUDE_PATH . 'classes/Language/LanguageUtility.class.php';
if (isset($_GET["id"])) {
    $pieces = explode('_', $_GET['id'], 2);
    $lang_code = $pieces[0];
    $charset = $pieces[1];
}
$languagesDAO = new LanguagesDAO();
$langCodesDAO = new LangCodesDAO();
// handle submits
if (isset($_POST['cancel'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php');
    exit;
} else {
    if (isset($_POST['save'])) {
        if (isset($_GET["id"])) {
            if ($languagesDAO->Update($lang_code, $charset, '', trim($_POST['native_name']), trim($_POST['english_name']), $_POST['status'])) {
                $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
                header('Location: index.php');
                exit;
            }
        } else {
Example #5
0
/************************************************************************/
/* Copyright (c) 2010                                                   */
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
include_once TR_INCLUDE_PATH . 'vitals.inc.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/DAO.class.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php';
global $msg, $addslashes;
$dao = new DAO();
$languagesDAO = new LanguagesDAO();
$languageTextDAO = new LanguageTextDAO();
//debug($_REQUEST);exit;
if (isset($_REQUEST['reset_filter'])) {
    unset($_REQUEST);
}
if (isset($_REQUEST['submit']) || isset($_REQUEST['search'])) {
    if (isset($_REQUEST['submit'])) {
        if (isset($_REQUEST['term_type']) && $_REQUEST['term_type'] != '') {
            $term_type = $_REQUEST['term_type'];
        }
        $sql = "SELECT * FROM " . TABLE_PREFIX . "language_text \n\t\t\t\t\t\tWHERE language_code='" . DEFAULT_LANGUAGE_CODE . "'";
        if ($term_type != '') {
            $sql .= " AND variable = '" . $term_type . "'";
        }
        if (isset($_REQUEST['new_or_translated']) && ($_REQUEST['new_or_translated'] == 1 || $_REQUEST['new_or_translated'] == 2)) {
Example #6
0
/* Copyright (c) 2010                                                   */
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
include TR_INCLUDE_PATH . 'vitals.inc.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
if (isset($_REQUEST['id'])) {
    $pieces = explode('_', $_REQUEST['id'], 2);
    $lang_code = $pieces[0];
    $charset = $pieces[1];
}
$languagesDAO = new LanguagesDAO();
if (isset($_POST['submit_no'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php');
    exit;
} else {
    if (isset($_POST['submit_yes'])) {
        if ($languagesDAO->Delete($lang_code)) {
            $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
            header('Location: index.php');
            exit;
        }
    }
}
$row = $languagesDAO->getByLangCodeAndCharset($lang_code, $charset);
unset($hidden_vars);
<?php

/************************************************************************/
/* AContent                                                             */
/************************************************************************/
/* Copyright (c) 2010                                                   */
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
include TR_INCLUDE_PATH . 'vitals.inc.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
if ($_POST['value'] == '') {
    $rtn['status'] = 'fail';
    $rtn['error'][] = _AT('TR_ERROR_EMPTY_FIELD');
}
if (isset($_POST['field']) && isset($_POST['value']) && $_POST['value'] != '') {
    $languagesDAO = new LanguagesDAO();
    // Format of $_POST['field']: [fieldName]|[language_code]|[charset]
    $pieces = explode(':', $_POST['field']);
    $languagesDAO->UpdateField($pieces[1], $pieces[0], $_POST['value']);
    $rtn['status'] = 'success';
    $rtn['success'][] = _AT('TR_FEEDBACK_ACTION_COMPLETED_SUCCESSFULLY');
}
echo json_encode($rtn);
 function import($filename)
 {
     require_once TR_INCLUDE_PATH . 'lib/pclzip.lib.php';
     require_once TR_INCLUDE_PATH . 'classes/Language/LanguageParser.class.php';
     require_once TR_INCLUDE_PATH . 'classes/DAO/LanguagesDAO.class.php';
     global $languageManager, $msg;
     $import_path = TR_CONTENT_DIR . 'import/';
     $archive = new PclZip($filename);
     if ($archive->extract(PCLZIP_OPT_PATH, $import_path) == 0) {
         exit('Error : ' . $archive->errorInfo(true));
     }
     $language_xml = @file_get_contents($import_path . 'language.xml');
     $languageParser = new LanguageParser();
     $languageParser->parse($language_xml);
     $languageEditor =& $languageParser->getLanguageEditor(0);
     $lang_code = $languageEditor->getCode();
     if ($languageManager->exists($lang_code)) {
         $msg->addError('LANG_EXISTS');
     }
     if (!$msg->containsErrors()) {
         $languageEditor->import($import_path . 'language_text.sql');
         $languagesDAO = new LanguagesDAO();
         $languagesDAO->UpdateField($lang_code, "status", TR_STATUS_ENABLED);
         $msg->addFeedback('IMPORT_LANG_SUCCESS');
         $version_in_pack = $languageEditor->getTransformableVersion();
         if ($version_in_pack != VERSION) {
             $msg->addFEEDBACK(array('LANG_MISMATCH_VERSION', $version_in_pack, VERSION));
         }
     }
     // remove the files:
     @unlink($import_path . 'language.xml');
     @unlink($import_path . 'language_text.sql');
     @unlink($import_path . 'readme.txt');
     @unlink($filename);
 }