示例#1
0
 public function loadDetailed($UsrUid)
 {
     try {
         $result = array();
         $oUser = UsersPeer::retrieveByPK($UsrUid);
         if (!is_null($oUser)) {
             $aFields = $oUser->toArray(BasePeer::TYPE_FIELDNAME);
             $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME);
             $this->setNew(false);
             $aIsoCountry = IsoCountry::findById($aFields['USR_COUNTRY']);
             $aIsoSubdivision = IsoSubdivision::findById($aFields['USR_COUNTRY'], $aFields['USR_CITY']);
             $aIsoLocation = IsoLocation::findById($aFields['USR_COUNTRY'], $aFields['USR_CITY'], $aFields['USR_LOCATION']);
             $aFields["USR_COUNTRY_NAME"] = !empty($aIsoCountry["IC_NAME"]) ? $aIsoCountry["IC_NAME"] : "";
             $aFields["USR_CITY_NAME"] = !empty($aIsoSubdivision["IS_NAME"]) ? $aIsoSubdivision["IS_NAME"] : "";
             $aFields["USR_LOCATION_NAME"] = !empty($aIsoLocation["IL_NAME"]) ? $aIsoLocation["IL_NAME"] : "";
             $result = $aFields;
             return $result;
         } else {
             //return $result;
             throw new Exception("The row '" . $UsrUid . "' in table USER doesn't exist!");
         }
     } catch (Exception $oError) {
         throw $oError;
     }
 }
示例#2
0
 public function export()
 {
     G::LoadSystem('i18n_po');
     G::LoadClass("system");
     //get labels MichelangeloFE
     try {
         $oTranslation = new Translation();
         $MichelangeloFE = PATH_HOME . "../workflow/public_html/lib/js";
         if (file_exists($MichelangeloFE)) {
             $labels = self::readLabelsDirectory($MichelangeloFE, true);
             foreach ($labels as $label) {
                 $oTranslation->addTranslation('LABEL', 'ID_MAFE_' . G::encryptOld($label), 'en', $label);
             }
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     //creating the .po file
     $sPOFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . MAIN_POFILE . '.' . $_GET['LOCALE'] . '.po';
     $poFile = new i18n_PO($sPOFile);
     $poFile->buildInit();
     $language = new Language();
     $locale = $_GET['LOCALE'];
     $_TARGET_LANG = $_GET['LOCALE'];
     $_BASE_LANG = 'en';
     if (strpos($locale, Translation::$localeSeparator) !== false) {
         list($LAN_ID, $IC_UID) = explode(Translation::$localeSeparator, $_GET['LOCALE']);
         $iCountry = new IsoCountry();
         $iCountryRecord = $iCountry->findById($IC_UID);
         if (!isset($iCountryRecord['IC_UID'])) {
             throw new Exception("Country Target ID '{$_GET['LAN_ID']}' doesn't exist!");
         }
         $sCountry = $iCountryRecord['IC_NAME'];
     } else {
         $LAN_ID = $locale;
         $sCountry = $IC_UID = '';
     }
     $langRecord = $language->findById($LAN_ID);
     if (!isset($langRecord['LAN_NAME'])) {
         throw new Exception("Language Target ID \"{$LAN_ID}\" doesn't exist!");
     }
     $sLanguage = $langRecord['LAN_NAME'];
     //setting headers
     $poFile->addHeader('Project-Id-Version', 'ProcessMaker ' . System::getVersion());
     $poFile->addHeader('POT-Creation-Date', '');
     $poFile->addHeader('PO-Revision-Date', date('Y-m-d H:i:s'));
     $poFile->addHeader('Last-Translator', '');
     $poFile->addHeader('Language-Team', 'Colosa Developers Team <*****@*****.**>');
     $poFile->addHeader('MIME-Version', '1.0');
     $poFile->addHeader('Content-Type', 'text/plain; charset=utf-8');
     $poFile->addHeader('Content-Transfer_Encoding', '8bit');
     $poFile->addHeader('X-Poedit-Language', ucwords($sLanguage));
     $poFile->addHeader('X-Poedit-Country', ucwords($sCountry));
     $poFile->addHeader('X-Poedit-SourceCharset', 'utf-8');
     $poFile->addHeader('Content-Transfer-Encoding', '8bit');
     $aLabels = array();
     $aMsgids = array('' => true);
     // selecting all translations records of base language 'en' on TRANSLATIONS table
     $oCriteria = new Criteria('workflow');
     $oCriteria->addSelectColumn(TranslationPeer::TRN_CATEGORY);
     $oCriteria->addSelectColumn(TranslationPeer::TRN_ID);
     $oCriteria->addSelectColumn(TranslationPeer::TRN_VALUE);
     $oCriteria->add(TranslationPeer::TRN_LANG, 'en');
     $oDataset = TranslationPeer::doSelectRS($oCriteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $targetLangRecords = array();
     // retrieve the translation for the target language
     if ($LAN_ID != 'en') {
         // only if it is different language than base language 'en'
         $c = new Criteria('workflow');
         $c->addSelectColumn(TranslationPeer::TRN_CATEGORY);
         $c->addSelectColumn(TranslationPeer::TRN_ID);
         $c->addSelectColumn(TranslationPeer::TRN_VALUE);
         $c->add(TranslationPeer::TRN_LANG, $_GET['LOCALE']);
         $ds = TranslationPeer::doSelectRS($c);
         $ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         while ($ds->next()) {
             $row = $ds->getRow();
             $targetLangRecords[$row['TRN_CATEGORY'] . '/' . $row['TRN_ID']] = $row['TRN_VALUE'];
         }
     }
     // get the respective translation for each english label
     while ($oDataset->next()) {
         $aRow1 = $oDataset->getRow();
         $trnCategory = trim($aRow1['TRN_CATEGORY']);
         # Validation, validate that the TRN_CATEGORY contains valid characteres
         preg_match("/^[0-9a-zA-Z_-]+/", $trnCategory, $sTestResult);
         // IF the translations id "TRN_ID" has invalid characteres or has not accepted categories
         if ($sTestResult[0] !== $trnCategory || $trnCategory != 'LABEL' && $trnCategory != 'JAVASCRIPT') {
             $oTranslation = new Translation();
             $oTranslation->remove($aRow1['TRN_CATEGORY'], $aRow1['TRN_ID'], 'en');
             //remove not accepted translations
             continue;
             //jump to next iteration
         }
         // retrieve the translation for the target language
         if ($LAN_ID != 'en') {
             // only if it is different language than base language 'en'
             if (isset($targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']])) {
                 $msgstr = $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] != '' ? $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] : $aRow1['TRN_VALUE'];
             } else {
                 $msgstr = $aRow1['TRN_VALUE'];
             }
         } else {
             //if not just copy the same
             $msgstr = $aRow1['TRN_VALUE'];
         }
         $msgid = trim($aRow1['TRN_VALUE']);
         $msgstr = trim($msgstr);
         if (isset($aMsgids[$msgid])) {
             $msgid = '[' . $aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID'] . '] ' . $msgid;
         }
         $poFile->addTranslatorComment('TRANSLATION');
         $poFile->addTranslatorComment($aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']);
         $poFile->addReference($aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']);
         $poFile->addTranslation(stripcslashes($msgid), stripcslashes($msgstr));
         $aMsgids[$msgid] = true;
     }
     //$timer->setMarker('end making 1th .po from db');
     //find all xml files into PATH_XMLFORM
     $aXMLForms = glob(PATH_XMLFORM . '*/*.xml');
     //from a sublevel to
     $aXMLForms2 = glob(PATH_XMLFORM . '*/*/*.xml');
     $aXMLForms = array_merge($aXMLForms, $aXMLForms2);
     $aEnglishLabel = array();
     $aOptions = array();
     $nodesNames = array();
     G::loadSystem('dynaformhandler');
     foreach ($aXMLForms as $xmlFormPath) {
         $xmlFormFile = str_replace(chr(92), '/', $xmlFormPath);
         $xmlFormFile = str_replace(PATH_XMLFORM, '', $xmlFormPath);
         $dynaForm = new dynaFormHandler($xmlFormPath);
         $dynaNodes = $dynaForm->getFields();
         //get all fields of each xmlform
         foreach ($dynaNodes as $oNode) {
             $sNodeName = $oNode->nodeName;
             //$arrayNode = $dynaForm->getArray($oNode, Array('type', $_BASE_LANG, $_BASE_LANG));
             $arrayNode = $dynaForm->getArray($oNode);
             //if has not native language translation
             if (!isset($arrayNode[$_BASE_LANG]) || !isset($arrayNode['type']) || isset($arrayNode['type']) && in_array($arrayNode['type'], $this->exceptionFields)) {
                 continue;
                 //just continue with the next node
             }
             // Getting the Base Origin Text
             if (!is_array($arrayNode[$_BASE_LANG])) {
                 $originNodeText = trim($arrayNode[$_BASE_LANG]);
             } else {
                 $langNode = $arrayNode[$_BASE_LANG][0];
                 $originNodeText = $langNode['__nodeText__'];
             }
             // Getting the Base Target Text
             if (isset($arrayNode[$_TARGET_LANG])) {
                 if (!is_array($arrayNode[$_TARGET_LANG])) {
                     $targetNodeText = trim($arrayNode[$_TARGET_LANG]);
                 } else {
                     $langNode = $arrayNode[$_TARGET_LANG][0];
                     $targetNodeText = $langNode['__nodeText__'];
                 }
             } else {
                 $targetNodeText = $originNodeText;
             }
             $nodeName = $arrayNode['__nodeName__'];
             $nodeType = $arrayNode['type'];
             $msgid = $originNodeText;
             // if the nodeName already exists in the po file, we need to create other msgid
             if (isset($aMsgids[$msgid])) {
                 $msgid = '[' . $xmlFormFile . '?' . $nodeName . '] ' . $originNodeText;
             }
             $poFile->addTranslatorComment($xmlFormFile . '?' . $nodeName);
             $poFile->addTranslatorComment($xmlFormFile);
             $poFile->addReference($nodeType . ' - ' . $nodeName);
             $poFile->addTranslation(stripslashes($msgid), stripslashes($targetNodeText));
             $aMsgids[$msgid] = true;
             //if this node has options child nodes
             if (isset($arrayNode[$_BASE_LANG]) && isset($arrayNode[$_BASE_LANG][0]) && isset($arrayNode[$_BASE_LANG][0]['option'])) {
                 $originOptionNode = $arrayNode[$_BASE_LANG][0]['option'];
                 //get the options
                 $targetOptionExists = false;
                 if (isset($arrayNode[$_TARGET_LANG]) && isset($arrayNode[$_TARGET_LANG][0]) && isset($arrayNode[$_TARGET_LANG][0]['option'])) {
                     $targetOptionNode = $arrayNode[$_TARGET_LANG][0]['option'];
                     $targetOptionExists = true;
                 }
                 if (!is_array($originOptionNode)) {
                     if (is_string($originOptionNode)) {
                         $poFile->addTranslatorComment($xmlFormFile . '?' . $nodeName . '-' . $originOptionNode);
                         $poFile->addTranslatorComment($xmlFormFile);
                         $poFile->addReference($nodeType . ' - ' . $nodeName . ' - ' . $originOptionNode);
                         $poFile->addTranslation(stripslashes($msgid), stripslashes($originOptionNode));
                     }
                 } else {
                     foreach ($originOptionNode as $optionNode) {
                         $optionName = $optionNode['name'];
                         $originOptionValue = $optionNode['__nodeText__'];
                         if ($targetOptionExists) {
                             $targetOptionValue = getMatchDropdownOptionValue($optionName, $targetOptionNode);
                             if ($targetOptionValue === false) {
                                 $targetOptionValue = $originOptionValue;
                             }
                         } else {
                             $targetOptionValue = $originOptionValue;
                         }
                         $msgid = '[' . $xmlFormFile . '?' . $nodeName . '-' . $optionName . ']';
                         $poFile->addTranslatorComment($xmlFormFile . '?' . $nodeName . '-' . $optionName);
                         $poFile->addTranslatorComment($xmlFormFile);
                         $poFile->addReference($nodeType . ' - ' . $nodeName . ' - ' . $optionName);
                         $poFile->addTranslation($msgid, stripslashes($targetOptionValue));
                     }
                 }
             }
         }
         //end foreach
     }
     G::auditLog("ExportLanguage", "Language: " . $_GET['LOCALE']);
     G::streamFile($sPOFile, true);
 }
示例#3
0
    public function loadDetailed ($UsrUid)
    {
        try {
            $result = array ();
            $oUser = UsersPeer::retrieveByPK( $UsrUid );

            if (! is_null( $oUser )) {
                $aFields = $oUser->toArray( BasePeer::TYPE_FIELDNAME );
                $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
                $this->setNew( false );

                $aIsoCountry = IsoCountry::findById( $aFields['USR_COUNTRY'] );
                $aIsoSubdivision = IsoSubdivision::findById( $aFields['USR_COUNTRY'], $aFields['USR_CITY'] );
                $aIsoLocation = IsoLocation::findById( $aFields['USR_COUNTRY'], $aFields['USR_CITY'], $aFields['USR_LOCATION'] );

                $aFields["USR_COUNTRY_NAME"]  = (!empty($aIsoCountry["IC_NAME"]))? $aIsoCountry["IC_NAME"] : "";
                $aFields["USR_CITY_NAME"]     = (!empty($aIsoSubdivision["IS_NAME"]))? $aIsoSubdivision["IS_NAME"] : "";
                $aFields["USR_LOCATION_NAME"] = (!empty($aIsoLocation["IL_NAME"]))? $aIsoLocation["IL_NAME"] : "";

                require_once PATH_RBAC . "model/Roles.php";
                $roles = new Roles();
                $role = $roles->loadByCode($aFields['USR_ROLE']);
                $aFields['USR_ROLE_NAME'] = $role['ROL_NAME'];

                $result = $aFields;

                return $result;
            } else {
                //return $result;
                throw (new Exception(G::LoadTranslation("ID_USER_UID_DOESNT_EXIST", SYS_LANG, array("USR_UID" => $UsrUid))));
            }
        } catch (Exception $oError) {
            throw ($oError);
        }
    }