public function languagesExportToFile()
 {
     global $ARGS, $baseDir;
     $setting = Models\Language::loadOne($ARGS['id']);
     if ($setting) {
         $language = $setting->c['language'];
         $filename = $baseDir . $setting->c['location'];
         $csv = "# " . date("Y-m-d H:i:s") . "\n";
         foreach (Models\Translation::getAll() as $id) {
             $translation = Models\Translation::loadOne($id);
             $trans = $translation->c[$language];
             if (!$trans || $trans == "") {
                 $trans = "";
                 //$translation->c["name"];
             }
             if (!preg_match('/[^a-z_\\-0-9]/i', $translation->c['name'])) {
                 $csv .= $translation->c['name'] . " = \"" . str_replace('"', '\\"', $trans) . "\"\n";
             }
         }
         $res = file_put_contents($filename, $csv);
         if ($res) {
             $setting->c['published'] = date("Y-m-d H:i:s");
             Models\Language::updateOne($setting);
             return array("status" => 1, "msg" => "Language file created");
         }
     }
     return array("status" => 0, "msg" => "Language file creation failed");
 }
 public function beforeHandler()
 {
     global $TEMPLATE, $AUTH, $CONFIG, $ARGS, $SESS;
     parent::beforeHandler();
     $permTable = $CONFIG->getValue("language_editor", "check_permission");
     $authKey = $CONFIG->getValue("language_editor", "auth_key");
     if (isset($permTable) && $permTable != "false") {
         $GLOBALS['AUTH'] = new Atabase\AuthManager($permTable);
         if (isset($authKey)) {
             $GLOBALS['AUTH']->init($authKey);
         } else {
             $GLOBALS['AUTH']->init();
         }
         $GLOBALS['AUTH']->mustBeLoggedIn();
         $GLOBALS['AUTH']->validate();
     }
     $TEMPLATE->assign("menu", "langeditor");
     $TEMPLATE->assign('submenu', '');
     $TEMPLATE->assign("activeMenu", "langEditor");
     $GLOBALS["LE_LANGS"] = Models\Language::loadAll(array("name" => "ASC"));
     $TEMPLATE->assign("LE_LANGS", $GLOBALS["LE_LANGS"]);
     $GLOBALS["LE_CATEGORIES"] = Models\LanguageCategory::loadAll(array("name" => "ASC"));
     $TEMPLATE->assign("LE_CATEGORIES", $GLOBALS["LE_CATEGORIES"]);
 }