public function __construct(NarroUser $objUser, $objParentObject, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = dirname(__FILE__) . '/' . __CLASS__ . '.tpl.php';
     $this->objUser = $objUser;
     $this->pnlTranslatedPerProjectPie = new QDatabasePieChart($this);
     $this->pnlTranslatedPerProjectPie->Query = sprintf('
                         SELECT
                             narro_project.project_name AS label, COUNT(narro_suggestion.suggestion_id) AS cnt
                         FROM
                             narro_suggestion, narro_context, narro_project
                         WHERE
                             narro_context.text_id = narro_suggestion.text_id AND
                             narro_project.project_id = narro_context.project_id AND
                             narro_suggestion.language_id=%d AND
                             narro_suggestion.user_id=%d
                         GROUP BY narro_context.project_id', QApplication::GetLanguageId(), $this->objUser->UserId);
     $intSuggestionCount = NarroSuggestion::CountByUserId($this->objUser->UserId);
     $this->pnlTranslatedPerProjectPie->Total = $intSuggestionCount;
     $this->pnlTranslatedPerProjectPie->MinimumDataValue = 0;
     $this->pnlApprovedPie = new QPieChart($this);
     $this->pnlApprovedPie->Total = $this->pnlTranslatedPerProjectPie->Total;
     $this->pnlApprovedPie->MinimumDataValue = 0;
     $objDatabase = NarroContextInfo::GetDatabase();
     $strQuery = sprintf("\n                            SELECT\n                                DISTINCT narro_context_info.valid_suggestion_id\n                            FROM\n                                narro_context_info, narro_suggestion\n                            WHERE\n                                narro_context_info.valid_suggestion_id=narro_suggestion.suggestion_id AND\n                                narro_suggestion.user_id=%d", $this->objUser->UserId);
     $objDbResult = $objDatabase->Query($strQuery);
     $intValidSuggestionCount = $objDbResult->CountRows();
     $this->pnlApprovedPie->Data = array(t('Approved') => $intValidSuggestionCount, t('Not approved') => $intSuggestionCount - $intValidSuggestionCount);
     $this->tabActivity = new QTabs($this);
     $this->dtgSuggestions_Create();
     $arrHeaders[] = t('Translations');
     $this->dtgReviews_Create();
     $arrHeaders[] = t('Reviews');
     $this->dtgComments_Create();
     $arrHeaders[] = t('Comments');
     $this->dtgVotes_Create();
     $arrHeaders[] = t('Votes');
     if (QApplication::HasPermissionForThisLang('Administrator') || QApplication::GetUserId() == $this->objUser->UserId) {
         $this->dtgLog_Create();
         $arrHeaders[] = t('Logged messages');
     }
     $this->tabActivity->Headers = $arrHeaders;
 }
 public function btnReset_Click($strFormId, $strControlId, $strParameter)
 {
     NarroContextInfo::GetDatabase()->Query(sprintf("DELETE FROM narro_context_info USING narro_context_info LEFT JOIN narro_context ON narro_context_info.context_id=narro_context.context_id WHERE narro_context_info.language_id=%d AND narro_context.project_id=%d", QApplication::GetLanguageId(), $this->objProject->ProjectId));
     $this->objProject->CountAllTextsByLanguage();
     $this->objProject->CountApprovedTextsByLanguage();
     $this->objProject->CountAllWordsByLanguage();
     $this->objProject->CountTranslatedTextsByLanguage();
     $this->lblMessage->Text = sprintf(t('The project was successfuly reset for %s. You need to import it again for this language to start over.'), QApplication::$TargetLanguage->LanguageName);
 }
 public function btnReplace_Click()
 {
     if (!QApplication::HasPermissionForThisLang('Can approve')) {
         return false;
     }
     if ($this->txtReplace->Display == false) {
         $this->txtReplace->Display = true;
     } else {
         if ($this->txtSearch->Text == '') {
             return false;
         }
         if ($this->txtReplace->Text == '') {
             return false;
         }
         $strQuery = NarroContextInfo::GetQueryForConditions($objQueryBuilder, QQ::AndCondition($this->arrConditions), $this->arrClauses);
         $objDbResult = NarroContextInfo::GetDatabase()->Query($strQuery);
         if ($objDbResult) {
             $intReplaceCnt = 0;
             $intApproved = 0;
             $intTranslations = 0;
             $arrProcessed = array();
             while ($objDbRow = $objDbResult->GetNextRow()) {
                 $objContextInfo = NarroContextInfo::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
                 if (in_array($objContextInfo->ContextInfoId, $arrProcessed)) {
                     continue;
                 } else {
                     $arrProcessed[] = $objContextInfo->ContextInfoId;
                 }
                 $objReplaceSuggestion = null;
                 if (preg_match("/^'.*'\$/", $this->txtSearch->Text)) {
                     $strToReplace = substr($this->txtSearch->Text, 1, -1);
                 } else {
                     $strToReplace = $this->txtSearch->Text;
                 }
                 if ($strToReplace == $objContextInfo->Context->Text->TextValue) {
                     $objReplaceSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($objContextInfo->Context->TextId, QApplication::GetLanguageId(), md5($this->txtReplace->Text));
                     if (!$objReplaceSuggestion) {
                         $objSuggestion = new NarroSuggestion();
                         $objSuggestion->UserId = QApplication::GetUserId();
                         $objSuggestion->TextId = $objContextInfo->Context->TextId;
                         $objSuggestion->LanguageId = QApplication::GetLanguageId();
                         $objSuggestion->SuggestionValue = $this->txtReplace->Text;
                         $objSuggestion->HasComments = 0;
                         $objSuggestion->IsImported = 0;
                         $objSuggestion->Created = QDateTime::Now();
                         $objSuggestion->Modified = null;
                         $objSuggestion->Save();
                         $intTranslations++;
                         $objReplaceSuggestion = $objSuggestion;
                     }
                 }
                 if ($objReplaceSuggestion instanceof NarroSuggestion) {
                     $intReplaceCnt++;
                     if ($objContextInfo->ValidSuggestionId != $objReplaceSuggestion->SuggestionId || $this->chkApprove->Checked) {
                         if ($objContextInfo->ValidSuggestionId == null) {
                             $intApproved++;
                         }
                         $objContextInfo->ValidSuggestionId = $objReplaceSuggestion->SuggestionId;
                         $objContextInfo->ValidatorUserId = QApplication::GetUserId();
                         $objContextInfo->Modified = QDateTime::Now();
                         $objContextInfo->Save();
                     }
                 }
             }
             $this->dtrText->RemoveChildControls(true);
             $this->btnReplace->Refresh();
             QApplication::ExecuteJavaScript(sprintf('jQuery(\'#%s\').after(\'&nbsp;<small style="padding: 2px;" class="ui-state-highlight ui-corner-all"><span style="width:16px; height: 16px; display:inline-block" class="ui-icon ui-icon-info"></span>&nbsp;%s.</small>\')', $this->btnReplace->ControlId, sprintf(t('%d occurences of "%s" translated with "%s", out of which %d were already approved, %d translations added.'), $intReplaceCnt, $strToReplace, $this->txtReplace->Text, $intApproved, $intTranslations)));
         }
     }
 }
    /**
     * Truncate narro_context_info table
     * @return void
     */
    public static function Truncate()
    {
        // Get the Database Object for this Class
        $objDatabase = NarroContextInfo::GetDatabase();
        // Perform the Query
        $objDatabase->NonQuery('
				TRUNCATE `narro_context_info`');
        if (QApplication::$objCacheProvider && QApplication::$Database[1]->Caching) {
            QApplication::$objCacheProvider->DeleteAll();
        }
    }