Exemple #1
0
 function getPermissions(&$record)
 {
     $user =& SweteTools::getUser();
     if (!isset($user)) {
         return null;
     }
     if (SweteTools::isAdmin()) {
         return null;
     }
     if (isset($record)) {
         require_once 'inc/SweteJob.class.php';
         require_once 'inc/SweteDb.class.php';
         if ($record->val('posted_by') === $user->val('username')) {
             //error_log($record->val("job_note_id")." note posted by ".$record->val('posted_by')   ." user ".$user->val('username'));
             return Dataface_PermissionsTool::getRolePermissions('OWNER');
         }
     }
     return Dataface_PermissionsTool::getRolePermissions('READ ONLY');
 }
 function handle($params)
 {
     @session_write_close();
     header('Connection:close');
     import('inc/SweteWebpage.class.php');
     $app = Dataface_Application::getInstance();
     $query = $app->getQuery();
     $records = df_get_selected_records($query);
     $errors = array();
     $failed = 0;
     $success = 0;
     if ($records) {
         foreach ($records as $rec) {
             if ($rec->table()->tablename != 'webpages') {
                 continue;
             }
             if (!$rec->checkPermission('swete:approve page')) {
                 $errors[] = $rec->getTitle() . ' could not be approved because you don\'t have permission.';
                 $failed++;
                 continue;
             }
             $site = $this->getSite($rec->val('website_id'));
             $username = '';
             $user = SweteTools::getUser();
             if ($user) {
                 $username = $user->val('username');
             }
             $wp = new SweteWebpage($rec);
             $twp = $wp->getTranslation($site->getDestinationLanguage());
             try {
                 $res = $twp->setStatus(SweteWebpage::STATUS_APPROVED, $username, @$_POST['--comments']);
                 $success++;
             } catch (Exception $ex) {
                 error_log($ex->getMessage());
                 $errors[] = 'Failed to approve page ' . $rec->getTitle() . '.  See error log for details.';
                 $failed++;
             }
         }
     }
     header('Content-type: text/json; charset="' . $app->_conf['oe'] . '"');
     echo json_encode(array('code' => 200, 'failed' => $failed, 'success' => $success, 'errors' => $errors));
 }
 function block__after_left_column()
 {
     //add info here when the user has an uncompiled job (or jobs).
     $app = Dataface_Application::getInstance();
     if ($app->_conf['enable_jobs']) {
         $jobs = SweteTools::uncompiledJobs();
         if (isset($jobs) && !empty($jobs)) {
             $url = df_absolute_url(DATAFACE_SITE_HREF . '?-table=jobs&-action=list&compiled=0&posted_by==' . SweteTools::getUser()->val('username'));
             echo '<div class="uncompiled-jobs">There are <a href="' . $url . '">' . count($jobs) . ' jobs ' . '</a>' . 'waiting to be compiled.</div>';
         }
     }
 }
Exemple #4
0
 function beforeInsert($record)
 {
     if (!$record->val('posted_by') and SweteTools::getUser()) {
         $record->setValue('posted_by', SweteTools::getUser()->val('username'));
     }
 }
Exemple #5
0
 function handle($params)
 {
     if (!SweteTools::getUser()) {
         return Dataface_Error::permissionDenied("You must log into access the dashboard");
     }
     $app = Dataface_Application::getInstance();
     // Get sites summary
     import('Dataface/ResultReader.php');
     /*
     $reader = new Dataface_ResultReader("select
     	ws.source_language,
     	ws.target_language,
     	ws.log_translation_misses,
     	ws.website_id, 
     	ws.website_name,
     	ws.website_url,
     	ws.translation_memory_id,
     	concat('http://',ws.host,ws.base_path) as proxy_url,
     	ws.source_language,
     	ws.target_language,
     	(
     		select count(*) from webpages w where w.website_id=ws.website_id
     	) as numpages,
     	(
     		select count(*) from swete_strings tml where tml.website_id=ws.website_id
     	) as numphrases,
     	ifnull((
     		select sum(tml.num_words) from xf_tm_strings xts 
     			inner join swete_strings tml on tml.string_id=xts.string_id
     		where tml.website_id=ws.website_id
     	), 0) as numwords,
     	(
     		select count(*) from swete_strings tml
     			inner join websites ws2 on ws2.website_id=tml.website_id
     			inner join xf_tm_translation_memory_strings xttms on xttms.translation_memory_id=ws2.translation_memory_id and xttms.string_id=tml.string_id
     		where xttms.current_translation_id is not null
     		 	and tml.website_id=ws.website_id
     		
     	) as translated_phrases,
     	
     	ifnull((
     		select sum(tml.num_words) from swete_strings tml
     			inner join websites ws2 on ws2.website_id=tml.website_id
     			inner join xf_tm_translation_memory_strings xttms on xttms.translation_memory_id=ws2.translation_memory_id and xttms.string_id=tml.string_id
     			inner join xf_tm_strings xts on xttms.string_id=xts.string_id
     		where xttms.current_translation_id is not null
     			and tml.website_id=ws.website_id
     			
     	), 0) as translated_words
     	
     		
     	from websites ws
     	", df_db());
     */
     $reader = new Dataface_ResultReader("select\n\t\t\tws.source_language,\n\t\t\tws.target_language,\n\t\t\tws.log_translation_misses,\n\t\t\tws.website_id, \n\t\t\tws.website_name,\n\t\t\tws.website_url,\n\t\t\tws.translation_memory_id,\n\t\t\tconcat('http://',ws.host,ws.base_path) as proxy_url,\n\t\t\tws.source_language,\n\t\t\tws.target_language\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\tfrom websites ws\n\t\t\t", df_db());
     $results = array();
     $languages = Dataface_Table::loadTable('websites')->getValuelist('languages');
     foreach ($reader as $row) {
         $results[] = $row;
         $row->untranslated_words = $row->numwords - $row->translated_words;
         $row->untranslated_phrases = $row->numphrases - $row->translated_phrases;
         $row->source_label = @$languages[$row->source_language] ? $languages[$row->source_language] : $row->source_language;
         $row->target_label = @$languages[$row->target_language] ? $languages[$row->target_language] : $row->target_language;
     }
     Dataface_JavascriptTool::getInstance()->import('swete/actions/dashboard.js');
     $res = df_q("select count(*) from webpages");
     list($numPages) = mysql_fetch_row($res);
     @mysql_free_result($res);
     $res = df_q("select count(*) num_phrases, sum(xts.num_words) as num_words from swete_strings tml \n\t\t\tleft join xf_tm_strings xts on tml.string_id=xts.string_id");
     list($numPhrases, $numWords) = mysql_fetch_row($res);
     @mysql_free_result($res);
     $res = df_q("select count(*) from websites");
     list($numSites) = mysql_fetch_row($res);
     @mysql_free_result($res);
     $res = df_q("select count(*) as numphrases, ifnull(sum(xts.num_words),0) as num_words from swete_strings tml \n\t\t\tinner join websites w on w.website_id=tml.website_id\n\t\t\tinner join xf_tm_translation_memory_strings xttms on w.translation_memory_id=xttms.translation_memory_id and xttms.string_id=tml.string_id\n\t\t\tinner join xf_tm_strings xts on xts.string_id=tml.string_id\n\t\t\twhere xttms.current_translation_id is not null");
     list($translatedPhrases, $translatedWords) = mysql_fetch_row($res);
     @mysql_free_result($res);
     df_display(array('results' => $results, 'systemStats' => array('numWords' => $numWords, 'numPhrases' => $numPhrases, 'numSites' => $numSites, 'numPages' => $numPages, 'translatedPhrases' => $translatedPhrases, 'translatedWords' => $translatedWords, 'untranslatedWords' => $numWords - $translatedWords, 'untranslatedPhrases' => $numPhrases - $translatedPhrases), 'swete_version' => file_get_contents('version.txt')), 'swete/actions/dashboard.html');
 }
Exemple #6
0
 public function start()
 {
     $username = '';
     $user = SweteTools::getUser();
     if ($user) {
         $username = $user->val('username');
     }
     $res = SweteDb::q("select running from background_processes where running=1 and username='******' limit 1");
     if (mysql_num_rows($res) > 0) {
         // There is already a process running... we'll bow out.
         return false;
     }
     @mysql_free_result($res);
     $res = SweteDb::q("update background_processes set running=1, time_started=NOW() where process_id='" . addslashes($this->processId) . "'");
     if (mysql_affected_rows(df_db()) == 0) {
         throw new Exception("Cannot run process " . $this->processId . " because it could not find itself in the background_processes table.");
     }
     register_shutdown_function(array($this, 'cleanup'));
     $this->clean = false;
     $this->run();
     SweteDb::q("update background_processes set complete=1, running=0, time_finished=NOW() where process_id='" . addslashes($this->processId) . "'");
     $this->cleanup();
     return true;
 }