Esempio n. 1
0
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     $mixResult = parent::Save($blnForceInsert, $blnForceUpdate);
     foreach (NarroProject::LoadAll() as $objProject) {
         $objProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($objProject->ProjectId, $this->LanguageId);
         if (!$objProjectProgress) {
             $objProject->CountAllTextsByLanguage($this->LanguageId);
         }
     }
     return $mixResult;
 }
 /**
  * This Form_Validate event handler allows you to specify any custom Form Validation rules.
  * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
  */
 protected function Form_Validate()
 {
     // By default, we report the result of validation from the parent
     $blnToReturn = parent::Form_Validate();
     // Custom Validation Rules
     // TODO: Be sure to set $blnToReturn to false if any custom validation fails!
     // Check for records that may violate Unique Clauses
     if (($objNarroProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($this->lstProject->SelectedValue, $this->lstLanguage->SelectedValue)) && $objNarroProjectProgress->ProjectProgressId != $this->mctNarroProjectProgress->NarroProjectProgress->ProjectProgressId) {
         $blnToReturn = false;
         $this->lstProject->Warning = QApplication::Translate("Already in Use");
         $this->lstLanguage->Warning = QApplication::Translate("Already in Use");
     }
     $blnFocused = false;
     foreach ($this->GetErrorControls() as $objControl) {
         // Set Focus to the top-most invalid control
         if (!$blnFocused) {
             $objControl->Focus();
             $blnFocused = true;
         }
         // Blink on ALL invalid controls
         $objControl->Blink();
     }
     return $blnToReturn;
 }
Esempio n. 3
0
}
QFirebug::setEnabled(false);
if (array_search('--help', $argv) !== false) {
    echo sprintf("php %s [options]\n" . "--project                    project id instead of exporting all projects\n" . "--language                   language code instead of importing all languages\n" . "--disable-plugins            disable plugins during import/export\n" . "                             suggestions, optional, defaults to anonymous\n" . "--exported-suggestion        1 for approved,\n" . "                             2 - approved, then most voted,\n" . "                             3 - approved, then most recent,\n" . "                             4 - approved, most voted, most recent,\n" . "                             5 - approved, my suggestion\n" . "--skip-untranslated          skip lines that don't have translated texts\n", basename(__FILE__), NarroLanguage::SOURCE_LANGUAGE_CODE);
    exit;
}
foreach (NarroProject::LoadArrayByActive(1) as $objProject) {
    if (in_array('--project', $argv) && $objProject->ProjectId != $argv[array_search('--project', $argv) + 1]) {
        continue;
    }
    foreach (NarroLanguage::LoadAllActive() as $objLanguage) {
        if (in_array('--language', $argv) && $objLanguage->LanguageCode != $argv[array_search('--language', $argv) + 1]) {
            continue;
        }
        QApplication::$TargetLanguage = $objLanguage;
        $objProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($objProject->ProjectId, $objLanguage->LanguageId);
        if (!$objProjectProgress || $objProjectProgress->Active) {
            try {
                $objNarroImporter = new NarroProjectImporter();
                $objNarroImporter->SkipUntranslated = (bool) array_search('--skip-untranslated', $argv);
                NarroPluginHandler::$blnEnablePlugins = !(bool) array_search('--disable-plugins', $argv);
                if (array_search('--exported-suggestion', $argv)) {
                    $objNarroImporter->ExportedSuggestion = $argv[array_search('--exported-suggestion', $argv) + 1];
                }
                $strSourceLanguage = NarroLanguage::SOURCE_LANGUAGE_CODE;
                if (array_search('--user', $argv) !== false) {
                    $intUserId = $argv[array_search('--user', $argv) + 1];
                }
                $objUser = NarroUser::LoadByUserId($intUserId);
                if (!$objUser instanceof NarroUser) {
                    NarroLogger::LogInfo(sprintf('User id=%s does not exist in the database, will try to use the anonymous user.', $intUserId));
Esempio n. 4
0
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'Preferences':
             return $this->arrPreferences;
         case 'ProjectProgressForCurrentLanguage':
             if (!$this->intProjectId) {
                 return false;
             }
             if (isset($this->objProjectProgressForCurrentLanguage)) {
                 return $this->objProjectProgressForCurrentLanguage;
             } else {
                 $this->objProjectProgressForCurrentLanguage = NarroProjectProgress::LoadByProjectIdLanguageId($this->intProjectId, QApplication::GetLanguageId());
                 if (!$this->objProjectProgressForCurrentLanguage instanceof NarroProjectProgress) {
                     $this->objProjectProgressForCurrentLanguage = new NarroProjectProgress();
                     $this->objProjectProgressForCurrentLanguage->LanguageId = QApplication::GetLanguageId();
                     $this->objProjectProgressForCurrentLanguage->ProjectId = $this->intProjectId;
                     $this->objProjectProgressForCurrentLanguage->TotalTextCount = 0;
                     $this->objProjectProgressForCurrentLanguage->ApprovedTextCount = 0;
                     $this->objProjectProgressForCurrentLanguage->FuzzyTextCount = 0;
                     $this->objProjectProgressForCurrentLanguage->ProgressPercent = 0;
                     $this->objProjectProgressForCurrentLanguage->LastModified = QDateTime::Now();
                     $this->objProjectProgressForCurrentLanguage->Active = $this->Active;
                     $this->objProjectProgressForCurrentLanguage->Save();
                 }
                 return $this->objProjectProgressForCurrentLanguage;
             }
         case 'DefaultTemplatePath':
             return __IMPORT_PATH__ . '/' . $this->ProjectId . '/' . NarroLanguage::SOURCE_LANGUAGE_CODE;
         case 'DefaultTranslationPath':
             return __IMPORT_PATH__ . '/' . $this->ProjectId . '/' . QApplication::$TargetLanguage->LanguageCode;
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     $this->UpdateNarroProjectFields();
     try {
         $this->objProject->Save();
         if ($this->pnlPreferences) {
             $this->pnlPreferences->btnSave_Click($strFormId, $strControlId, $strParameter);
         }
     } catch (Exception $objEx) {
         $this->lblMessage->Text = $objEx->getMessage();
         return false;
     }
     $objProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($this->objProject->ProjectId, QApplication::GetLanguageId());
     $objProjectProgress->Active = $this->txtActive->Checked;
     $objProjectProgress->Save();
     if ($this->strTitleVerb == t('Add')) {
         /**
          * If a new project is added, the project directory and source and target are created
          * Also sample export.sh and import.sh are written in the project directory, ready for use
          */
         $strProjectDir = realpath(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId);
         if (!file_exists($strProjectDir)) {
             mkdir($strProjectDir, 0777);
             chmod($strProjectDir, 0777);
             file_put_contents($strProjectDir . '/export.sh', "#!/bin/bash\n" . "#\n" . "PROJECT_DIR=\$(readlink -f \$0)\n" . "PROJECT_DIR=`dirname {$PROJECT_DIR}`\n" . "PARENT_DIR=`dirname {$PROJECT_DIR}`\n" . "PROJECT_ID=`basename {$PROJECT_DIR}`\n" . "\n" . "cd {$PROJECT_DIR}\n" . "\n" . "# \$1 - language code\n" . "# \$2 - language id\n" . "# \$3 - project name\n" . "# \$4 - project id\n" . "# \$5 - user id\n" . "\n" . sprintf("echo \"You can run commands before import or after export by editing export.sh and import.sh from '%s'\"\n", $strProjectDir) . "export retVal=\$?\n" . "# the script will exit with the echo command exit code, 0 = successful run\n" . "exit \$retVal");
             copy($strProjectDir . '/export.sh', $strProjectDir . '/import.sh');
             chmod($strProjectDir . '/export.sh', 0666);
             chmod($strProjectDir . '/import.sh', 0666);
             if (!file_exists($strProjectDir . '/' . NarroLanguage::SOURCE_LANGUAGE_CODE)) {
                 mkdir($strProjectDir . '/' . NarroLanguage::SOURCE_LANGUAGE_CODE, 0777);
             }
             if (!file_exists($strProjectDir . '/' . QApplication::GetLanguageId())) {
                 mkdir($strProjectDir . '/' . QApplication::GetLanguageId(), 0777);
             }
         }
         QApplication::Redirect(NarroLink::ProjectImport($this->objProject->ProjectId));
     }
     if ($this->pnlTextsSource) {
         $this->pnlTextsSource->Directory;
     }
     $this->lblMessage->Text = t('Project saved sucessfully.');
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     foreach ($this->arrControls as $strName => $objControl) {
         switch (NarroProject::$AvailablePreferences[$strName]['type']) {
             case 'number':
                 $this->objProject->SetPreferenceValueByName($strName, $objControl->Text);
                 break;
             case 'text':
                 $this->objProject->SetPreferenceValueByName($strName, $objControl->Text);
                 break;
             case 'option':
                 $this->objProject->SetPreferenceValueByName($strName, $objControl->SelectedValue);
                 break;
         }
     }
     try {
         $this->objProject->Save();
         $this->objProject = NarroProject::Load($this->objProject->ProjectId);
         $this->objProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($this->objProject->ProjectId, QApplication::GetLanguageId());
         $this->lblMessage->Text = t('Your preferences were saved successfuly.');
         $this->lblMessage->ForeColor = 'green';
     } catch (Exception $objEx) {
         $this->lblMessage->Text = t('An error occurred while trying to save your preferences.');
         $this->lblMessage->ForeColor = 'red';
     }
 }