/** * Builds a link based on the given query. * @param Associative array of the query. (also accepts a query string e.g.: 'Name=Steve&LastName=Hannah'). * @param useContext If true, this query will use the existing REQUEST parameters as a base. */ public static function buildLink($query, $useContext = true, $forceContext = false, $stripRecordId = false) { $app =& Dataface_Application::getInstance(); $appQuery =& $app->getQuery(); if ($stripRecordId and isset($query['-recordid'])) { unset($query['-recordid']); } if (is_string($query)) { $terms = explode('&', $query); $query = array(); foreach ($terms as $term) { $key = urldecode(substr($term, 0, strpos($term, '='))); $value = urldecode(substr($term, strpos($term, '=') + 1)); if (strlen($value) == 0) { $query[$key] = null; } else { $query[$key] = $value; } } } if (!isset($query['-table'])) { $query['-table'] = $appQuery['-table']; } if (!$forceContext and $useContext) { // We check if the query parameters have changed. If they have, then it doesn't // make a whole lot of sense to maintain context. foreach ($query as $key => $val) { if (!$key) { continue; } if ($key[0] != '-' and $query[$key] != @$appQuery[$key]) { $useContext = false; break; } } } if ($useContext) { $request = Dataface_LinkTool::getMask(); if ($stripRecordId and isset($request['-recordid'])) { unset($request['-recordid']); } if (isset($query['-relationship'])) { if ($query['-relationship'] != @$appQuery['-relationship']) { foreach ($request as $qkey => $qval) { if (strstr($qkey, '-related:') == $qkey) { unset($request[$qkey]); } } } } if (isset($request['-sort']) and $request['-table'] != $appQuery['-table']) { unset($request['-sort']); } //print_r($query); $query = array_merge($request, $query); } if (!isset($query['-search'])) { $query['-search'] = null; } if (isset($_REQUEST['-search']) and strlen($_REQUEST['-search']) > 0 and $query['-search'] !== null) { $query['-search'] = $_REQUEST['-search']; } foreach ($query as $key => $value) { if ($value === null || strpos($key, '--') === 0) { unset($query[$key]); } } $str = ''; foreach ($query as $key => $value) { if (is_array($value)) { foreach ($value as $vkey => $vval) { $str .= urlencode($key . '[' . $vkey . ']') . '=' . urlencode($vval) . '&'; } } else { $str .= urlencode($key) . '=' . urlencode($value) . '&'; } } $str = substr($str, 0, strlen($str) - 1); $url = DATAFACE_SITE_HREF; if (strpos('?', $url) !== false) { $url .= '&' . $str; } else { $url .= '?' . $str; } $url = $app->filterUrl($url); return df_absolute_url($url); }
function handle($params) { $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $this->table =& Dataface_Table::loadTable($query['-table']); $translations =& $this->table->getTranslations(); foreach (array_keys($translations) as $trans) { $this->table->getTranslation($trans); } //print_r($translations); if (!isset($translations) || count($translations) < 2) { // there are no translations to be made trigger_error('Attempt to translate a record in a table "' . $this->table->tablename . '" that contains no translations.', E_USER_ERROR); } $this->translatableLanguages = array_keys($translations); $translatableLanguages =& $this->translatableLanguages; $this->languageCodes = new I18Nv2_Language($app->_conf['lang']); $languageCodes =& $this->languageCodes; $currentLanguage = $languageCodes->getName($app->_conf['lang']); if (count($translatableLanguages) < 2) { return PEAR::raiseError(df_translate('Not enough languages to translate', 'There aren\'t enough languages available to translate.'), DATAFACE_E_ERROR); } $defaultSource = $translatableLanguages[0]; $defaultDest = $translatableLanguages[1]; $options = array(); foreach ($translatableLanguages as $lang) { $options[$lang] = $languageCodes->getName($lang); } $form = new HTML_QuickForm('TranslationForm', 'POST'); $form->addElement('select', '-sourceLanguage', 'Source Language', $options); $form->addElement('select', '-destinationLanguage', 'Destination Language', $options); $form->setDefaults(array('-sourceLanguage' => $defaultSource, '-destinationLanguage' => $defaultDest)); $form->addElement('submit', '-translate', 'Translate'); $mask =& Dataface_LinkTool::getMask(); // The mask of parameters that are passed to new urls // We need to modify this mask so that the appropriate parameters are passed. foreach ($query as $key => $value) { $form->addElement('hidden', $key); $form->setDefaults(array($key => $value)); } if ($form->validate()) { $res = $form->process(array(&$this, 'processForm')); if (PEAR::isError($res)) { if ($query['--format'] == 'rest') { header('Content-type: text/plain'); echo 'FAILED' . "\n" . $res->getMessage(); exit; } return $res; } else { //print_r($form->exportValues()); //echo "Done";exit; if ($query['--format'] == 'rest') { header('Content-type: text/plain'); echo 'SUCCEEDED' . "\nRecords Successfully Translated"; exit; } header('Location: ' . $app->url('-action=list&-sourceLanguage=&-destinationLanguage=&-translate=') . '&--msg=Records successfully translated'); exit; } } ob_start(); $form->display(); $out = ob_get_contents(); ob_end_clean(); df_display(array('body' => $out), 'Dataface_Main_Template.html'); }