示例#1
0
 function run()
 {
     $sError = false;
     $this->setTitle($this->t_('title'));
     if (AnwEnv::_POST("submit")) {
         $sLogin = AnwEnv::_POST("login", "");
         $sPassword = AnwEnv::_POST("password", "");
         $bRememberMe = AnwSessions::isResumeEnabled() && AnwEnv::_POST("remember") ? true : false;
         $sUrlRedirect = AnwEnv::_POST("redirect", "");
         try {
             //try to authenticate and open the session
             AnwCurrentSession::login($sLogin, $sPassword, $bRememberMe);
             $this->redirectInfo($sUrlRedirect, $this->t_("t_loggedin"), $this->t_("p_loggedin"));
         } catch (AnwAuthException $e) {
             $sError = $this->g_("err_auth");
         } catch (AnwBadLoginException $e) {
             $sError = $this->g_("err_badlogin");
         } catch (AnwBadPasswordException $e) {
             $sError = $this->g_("err_badpassword");
         }
         //error occurred, display again the login form
         $this->showLoginForm($sLogin, $sUrlRedirect, $bRememberMe, $sError);
     } else {
         //arriving on the form
         $this->showLoginForm("", AnwEnv::_GET("redirect", ""), false);
     }
 }
示例#2
0
 function getValuesFromPost($sInputName)
 {
     $asValues = AnwEnv::_POST($sInputName, array());
     foreach ($asValues as $i => $sValue) {
         $asValues[$i] = $this->cleanValueFromPost($sValue);
     }
     return $asValues;
 }
示例#3
0
 function run()
 {
     // load CSS
     $this->head($this->getCssSrcComponent(self::CSS_FILENAME));
     $this->setTitle($this->t_("title"));
     if (!AnwEnv::_POST("exportpages")) {
         $this->exportForm();
     } else {
         $this->exportProcess(AnwEnv::_POST("exportpages"));
     }
 }
示例#4
0
 function run()
 {
     $this->lockPageForEdition(AnwLock::TYPE_PAGEGROUP);
     $this->setTitle($this->t_('title', array("pagename" => $this->getPageName())));
     //decide what to do
     if (AnwEnv::_POST("abort")) {
         $this->abortChangeLang();
     } else {
         if (AnwEnv::_POST("newlang") && AnwEnv::_POST("newlang") != $this->getoPage()->getLang()) {
             $this->doChangeLang(AnwEnv::_POST("newlang", ""), AnwEnv::_POST("comment", ""));
         } else {
             $this->changeLangForm(AnwEnv::_POST("newlang", $this->getoPage()->getLang()), AnwEnv::_POST("comment", ""));
         }
     }
 }
示例#5
0
 function run()
 {
     $this->lockPageForEdition(AnwLock::TYPE_PAGEGROUP);
     $this->setTitle($this->t_('title', array('pagename' => $this->getPageName())));
     //decide what to do
     if (AnwEnv::_POST("abort")) {
         $this->abortRename();
     } else {
         if (AnwEnv::_POST("newname") && AnwEnv::_POST("newname") != $this->getoPage()->getName()) {
             $this->doRename(AnwEnv::_POST("newname", ""), AnwEnv::_POST("comment", ""), (bool) AnwEnv::_POST("updatelinks", true));
         } else {
             $this->renameForm(AnwEnv::_POST("newname", $this->getoPage()->getName()), AnwEnv::_POST("comment", ""));
         }
     }
 }
示例#6
0
 function run()
 {
     loadApp($this->getMyComponentPathDefault() . 'class_stepinstall.php');
     //make sure it's not already installed
     if (file_exists(ANWIKI_INSTALL_LOCK)) {
         $sLinkHome = AnwUtils::link(AnwComponent::globalCfgHomePage());
         $sLinkForce = AnwStepInstall::linkStep(AnwStepInstall::getStepDefault());
         $this->out .= $this->tpl()->alreadyInstalled($sLinkHome, $sLinkForce, ANWIKI_INSTALL_LOCK, ANWIKI_INSTALL_STATUS);
         return;
     }
     //make sure writable dir is writable
     if (!file_exists(ANWIKI_INSTALL_STATUS)) {
         @touch(ANWIKI_INSTALL_STATUS);
     }
     if (!is_writable(ANWPATH_WRITABLE) || !is_writable(ANWIKI_INSTALL_STATUS)) {
         $this->out .= $this->tpl()->error($this->t_("err_notwritable_directory_explain", array('directory' => '<br/>' . ANWPATH_WRITABLE)), $this->t_("err_notwritable_t"));
         return;
     }
     //security
     define('ANWIKI_IN_INSTALL', true);
     //read next step
     $nCurrentStepStatus = self::getCurrentStepStatus();
     self::debug("current step status: " . $nCurrentStepStatus);
     //find step to execute
     $nStepOrder = (int) AnwEnv::_GET("step", AnwEnv::_POST("step", $nCurrentStepStatus));
     //do not go to next steps if previous steps were not completed
     if ($nStepOrder > $nCurrentStepStatus) {
         $nStepOrder = $nCurrentStepStatus;
     }
     //make sure step exists
     try {
         $sStepName = AnwStepInstall::getStepForOrder($nStepOrder);
     } catch (AnwException $e) {
         $nStepOrder = $nCurrentStepStatus;
         $sStepName = AnwStepInstall::getStepForOrder($nStepOrder);
     }
     //load the step
     $this->oStepInstall = AnwStepInstall::loadComponent($sStepName);
     AnwStepInstall::setActionInstall($this);
     $nCountSteps = count(AnwStepInstall::getAllSteps());
     $sLinkPrevious = $this->oStepInstall->linkStepPrevious();
     $sLinkNext = $this->oStepInstall->linkStepNext();
     $sTitleStep = $this->oStepInstall->getStepTitle();
     $this->out .= $this->tpl()->headerInstall($sTitleStep, $nStepOrder, $nCountSteps, $sLinkPrevious, $sLinkNext);
     //run the step
     $this->out .= $this->oStepInstall->runStepInstall();
     $this->out .= $this->tpl()->footerInstall($sTitleStep, $nStepOrder, $nCountSteps, $sLinkPrevious, $sLinkNext);
 }
示例#7
0
 function run()
 {
     if (AnwEnv::_POST("ping")) {
         if (AnwEnv::_POST("ping") == "yes") {
             $bAddInDirectory = AnwEnv::_POST("addindirectory") ? true : false;
             $this->doPing($bAddInDirectory);
         } else {
             $this->skipPing();
         }
     } else {
         if (AnwEnv::_GET("pingdone")) {
             $this->pingDone();
         } else {
             $this->showPingInfo();
         }
     }
 }
示例#8
0
 function run()
 {
     if (!self::globalCfgUsersRegisterEnabled()) {
         AnwUtils::redirect();
     }
     $this->setTitle($this->t_('title'));
     $sError = false;
     $sLogin = "";
     $sDisplayName = "";
     $sEmail = "";
     if (AnwEnv::_POST("submit")) {
         $sLogin = AnwEnv::_POST("login", "");
         $sDisplayName = AnwEnv::_POST("displayname", "");
         $sEmail = AnwEnv::_POST("email", "");
         $sPassword = AnwEnv::_POST("password", "");
         //try to register
         try {
             $this->checkCaptcha();
             $sLang = AnwCurrentSession::getLang();
             $nTimezone = AnwCurrentSession::getTimezone();
             $oUser = AnwUsers::createUser($sLogin, $sDisplayName, $sEmail, $sLang, $nTimezone, $sPassword);
             AnwCurrentSession::login($sLogin, $sPassword, false);
             //open a public time-limited session
             $this->redirectInfo(false, $this->t_("t_created"), $this->t_("p_created"));
         } catch (AnwLoginAlreadyTakenException $e) {
             $sError = $this->g_("err_loginalreadytaken");
         } catch (AnwBadLoginException $e) {
             $sError = $this->g_("err_badlogin");
         } catch (AnwDisplayNameAlreadyTakenException $e) {
             $sError = $this->g_("err_displaynamealreadytaken");
         } catch (AnwBadDisplayNameException $e) {
             $sError = $this->g_("err_baddisplayname");
         } catch (AnwEmailAlreadyTakenException $e) {
             $sError = $this->g_("err_emailalreadytaken");
         } catch (AnwBadEmailException $e) {
             $sError = $this->g_("err_bademail");
         } catch (AnwBadPasswordException $e) {
             $sError = $this->g_("err_badpassword");
         } catch (AnwBadCaptchaException $e) {
             $sError = $this->g_("err_badcaptcha");
         }
     }
     //display register form
     $this->out .= $this->tpl()->registerForm(AnwUtils::alink("register"), $sLogin, $sDisplayName, $sEmail, $sError);
 }
示例#9
0
 function run()
 {
     //find TO revision
     try {
         //retrieve pagegroup
         $nPageGroupId = (int) AnwEnv::_GET("pagegroup", AnwEnv::_POST("pagegroup"));
         if (!$nPageGroupId) {
             //special case: we may have passed a pageid (ie: from lastchanges, for better performances avoiding loading pagegroup info)
             $nPageId = (int) AnwEnv::_GET("page");
             if ($nPageId) {
                 $oExistingPageTmp = AnwPage::getLastPageRevision($nPageId);
                 //high queries consuming, not 100% cached...
                 if ($oExistingPageTmp->exists()) {
                     $nPageGroupId = $oExistingPageTmp->getPageGroup()->getId();
                 }
                 unset($oExistingPageTmp);
             }
             if (!$nPageGroupId) {
                 throw new AnwBadCallException();
             }
         }
         $oPageGroup = new AnwPageGroup($nPageGroupId);
         if (!$oPageGroup->exists()) {
             throw new AnwBadCallException("pagegroup not found for revert");
         }
         //get valid changeid
         $aoPageGroupChangesById = AnwStorage::getLastChanges(false, 0, null, null, null, null, $oPageGroup);
         $nRevToChangeId = (int) AnwEnv::_GET("revto", AnwEnv::_POST("revto"));
         //may be null when coming from action_revertpage
         if (!$nRevToChangeId || !array_key_exists($nRevToChangeId, $aoPageGroupChangesById)) {
             //get last changeid from this pagegroup
             $oChangeReference = reset($aoPageGroupChangesById);
             $nRevToChangeId = $oChangeReference->getChangeId();
         }
     } catch (AnwException $e) {
         throw new AnwBadCallException();
     }
     $this->setTitle($this->t_("title"));
     $aaRevertPlan = $this->generateRevertPlan($oPageGroup, $nRevToChangeId);
     if (AnwEnv::_POST("submit") && $nRevToChangeId > 0) {
         $this->doRevert($oPageGroup, $aaRevertPlan);
     } else {
         $this->showFormRevert($oPageGroup, $aaRevertPlan, $nRevToChangeId);
     }
 }
 function run()
 {
     if (AnwAcls::isDriverReadWrite()) {
         if (AnwEnv::_POST("submit_create") && AnwUsers::isDriverInternal()) {
             $this->createAndGrant(AnwEnv::_POST("login"), AnwEnv::_POST("displayname"), AnwEnv::_POST("email"), AnwEnv::_POST("password"));
         } else {
             if (AnwEnv::_POST("submit_existing")) {
                 $this->chooseAndGrant(AnwEnv::_POST("login"), AnwEnv::_POST("password"));
             } else {
                 if (AnwEnv::_GET("skipgrant")) {
                     $this->skipGrant();
                 } else {
                     $this->showChooseGrant();
                 }
             }
         }
     } else {
         $this->showGrantNotSupported();
     }
 }
示例#11
0
 function run()
 {
     // load CSS
     $this->head($this->getCssSrcComponent(self::CSS_FILENAME));
     //decide what to do
     if (AnwEnv::_GET("refresh")) {
         $this->refreshComponentsList();
     } else {
         try {
             $this->oComponent = null;
             $this->sComponentName = strtolower(AnwEnv::_GET("c", AnwEnv::_POST("c")));
             $this->sComponentType = strtolower(AnwEnv::_GET("t", AnwEnv::_POST("t")));
             if ($this->sComponentName && $this->sComponentType) {
                 try {
                     $this->oComponent = AnwComponent::loadComponentGeneric($this->sComponentName, $this->sComponentType);
                 } catch (AnwException $e) {
                 }
             }
             if (!$this->oComponent) {
                 $this->oComponent = AnwComponent::loadComponentGeneric('global', 'global');
             }
             if (AnwEnv::_POST("publish")) {
                 $this->saveEdition();
             } else {
                 if (AnwEnv::_GET("js") == "addmultiplecontentfield") {
                     $sFieldName = AnwEnv::_GET("fieldname");
                     $sSuffix = AnwEnv::_GET("suffix");
                     $this->JS_AddMultipleContentField($sFieldName, $sSuffix);
                 } else {
                     $this->editForm();
                 }
             }
         } catch (AnwInvalidContentException $e) {
             $this->editForm($this->g_("err_contentinvalid"));
         }
     }
 }
示例#12
0
 protected function saveEdition($sComment, $nDraftTime)
 {
     try {
         //check captcha
         if ($this->needsCaptcha()) {
             $this->checkCaptcha();
         }
         //update content from post
         $oEditContent = $this->getEditionForm()->updateContentFromEdition();
         //save changes
         $this->getoPage()->saveEditAndDeploy($oEditContent, AnwChange::TYPE_PAGE_EDITION, $sComment);
         //delete old draft
         /*if ($nDraftTime)
         		{
         			$oDraft = $this->getoPage()->getDraft($nDraftTime);
         			$oDraft->delete();
         		}*/
         //unlock
         $this->unlockPageForEdition();
         //redirect
         AnwUtils::redirect(AnwUtils::link($this->getoPage()));
     } catch (AnwStructuredContentEditionFormException $e) {
         $sError = $e->getMessage();
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     } catch (AnwBadCaptchaException $e) {
         $sError = $this->g_("err_badcaptcha");
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     } catch (AnwBadCommentException $e) {
         $sError = $this->g_("err_badcomment");
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     } catch (AnwUnexpectedException $e) {
         $sError = $this->g_("err_ex_unexpected_p");
         $nErrorNumber = AnwDebug::reportError($e);
         if ($nErrorNumber) {
             $sError .= '<br/>' . $this->g_("err_ex_report", array("errornumber" => $nErrorNumber));
         }
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     }
 }
示例#13
0
 private function updateSettings()
 {
     //update prefs
     $asErrorsPrefs = array();
     try {
         $sLang = AnwEnv::_POST("lang", "");
         AnwCurrentSession::setLang($sLang);
         $nTimezone = AnwEnv::_POST("timezone", 0);
         AnwCurrentSession::setTimezone($nTimezone);
     } catch (AnwBadLangException $e) {
         $asErrorsPrefs[] = $this->g_("err_badlang");
     } catch (AnwBadTimezoneException $e) {
         $asErrorsPrefs[] = $this->g_("err_badtimezone");
     } catch (AnwException $e) {
         $asErrorsPrefs[] = $this->g_("err_unkn");
     }
     $asErrorsAccount = array();
     if (AnwCurrentSession::isLoggedIn() && AnwUsers::isDriverInternal()) {
         //update account
         try {
             //displayname change requested ?
             if (self::globalCfgUsersChangeDisplayname()) {
                 $sDisplayname = AnwEnv::_POST("displayname", "");
                 if (AnwCurrentSession::getUser()->getDisplayName() != $sDisplayname) {
                     AnwCurrentSession::getUser()->changeDisplayName($sDisplayname);
                 }
             }
             //email change requested ?
             $sEmail = AnwEnv::_POST("email", "");
             if (AnwCurrentSession::getUser()->getEmail() != $sEmail) {
                 AnwCurrentSession::getUser()->changeEmail($sEmail);
             }
             //password change requested ?
             $sNewPassword = AnwEnv::_POST("newpassword");
             $sNewPasswordRepeat = AnwEnv::_POST("newpassword_repeat");
             $sCurrentPassword = AnwEnv::_POST("currentpassword", "");
             if ($sNewPassword) {
                 if ($sNewPassword == $sNewPasswordRepeat) {
                     try {
                         //authenticate with current password
                         AnwCurrentSession::getUser()->authenticate($sCurrentPassword);
                         //authentication ok, change the password
                         try {
                             AnwCurrentSession::getUser()->changePassword($sNewPassword);
                         } catch (AnwBadPasswordException $e) {
                             $asErrorsAccount[] = $this->t_("err_badnewpassword");
                         }
                     } catch (AnwBadPasswordException $e) {
                         $asErrorsAccount[] = $this->g_("err_incorrectpassword");
                     } catch (AnwAuthException $e) {
                         $asErrorsAccount[] = $this->g_("err_incorrectpassword");
                     }
                 } else {
                     $asErrorsAccount[] = $this->g_("err_passwordsmatch");
                 }
             }
         } catch (AnwDisplayNameAlreadyTakenException $e) {
             $asErrorsAccount[] = $this->g_("err_displaynamealreadytaken");
         } catch (AnwBadDisplayNameException $e) {
             $asErrorsAccount[] = $this->g_("err_baddisplayname");
         } catch (AnwEmailAlreadyTakenException $e) {
             $asErrorsAccount[] = $this->g_("err_emailalreadytaken");
         } catch (AnwBadEmailException $e) {
             $asErrorsAccount[] = $this->g_("err_bademail");
         } catch (AnwException $e) {
             $asErrorsAccount[] = $this->g_("err_unkn");
         }
     }
     if (count($asErrorsPrefs) > 0 || count($asErrorsAccount) > 0) {
         $this->formSettings(false, $asErrorsPrefs, $asErrorsAccount);
     } else {
         AnwUtils::redirect($this->linkMe(array("done" => 1)));
     }
 }
示例#14
0
 static function testCaptcha()
 {
     //retrieve typed number
     $nTestedNumber = AnwEnv::_POST("captcha");
     if (!$nTestedNumber) {
         $nTestedNumber = AnwEnv::_GET("captcha", 0);
     }
     $nTestedNumber = "{$nTestedNumber}";
     //compare
     $bTest = AnwEnv::_SESSION(self::SESSION_CAPTCHA) && AnwEnv::_SESSION(self::SESSION_CAPTCHA) == md5($nTestedNumber);
     AnwEnv::unsetSession(self::SESSION_CAPTCHA);
     return $bTest;
 }
示例#15
0
 function runAndOutput()
 {
     try {
         AnwDebug::startbench("action runAndOutput", true);
         //captcha request?
         if (AnwEnv::_GET(self::GET_CAPTCHA)) {
             $this->doCaptcha();
             exit;
         }
         //make sure this action is enabled in configuration
         if (!in_array($this->getName(), AnwComponent::getEnabledComponents(AnwComponent::TYPE_ACTION))) {
             throw new AnwAclException("Trying to execute an action which is not enabled");
         }
         //is it an admin action?
         if ($this instanceof AnwAdminAction) {
             if (!AnwCurrentSession::getUser()->isAdminAllowed()) {
                 throw new AnwAclException("Admin is not allowed");
             }
         }
         //does action require https if available?
         if (self::isHttpsAction($this->getName())) {
             //do we need to redirect to https?
             if (self::globalCfgHttpsEnabled() && !AnwEnv::isHttps()) {
                 //redirect to https
                 self::debug("Redirecting to https...");
                 AnwUtils::httpPostToSession();
                 $asParams = $_GET;
                 $sLink = AnwUtils::alink($this->getName(), $asParams);
                 AnwUtils::redirect($sLink);
                 //should automatically use https
             }
         }
         if (AnwCurrentSession::needsReauth()) {
             //reauth processing
             if (AnwEnv::_POST("reauth")) {
                 self::debug("Processing reauth request...");
                 try {
                     //check password and reset reauth
                     $this->doReauth(AnwEnv::_POST("reauth"));
                     self::debug("Reauth request success!");
                 } catch (AnwException $e) {
                     //reauth failed, show reauth form again
                     self::debug("Reauth success failed.");
                     $this->doReauthForm();
                     //post data is already in session
                     exit;
                 }
             }
             //must the user reauth for this action? - do this after reauth processing
             if ($this instanceof AnwHarmlessAction) {
                 //ok, user is authorized to run action without reauthenticating
             } else {
                 //user needs to reauthenticate
                 $this->checkReauth();
             }
         }
         //restore POST if any in session
         AnwUtils::restoreHttpPostFromSession();
         $this->initializeAction();
         //run the action
         $this->init();
         $this->run();
         AnwDebug::stopbench("action runAndOutput");
         $this->output();
     } catch (AnwLockException $e) {
         $aoLocks = $e->getLocks();
         $asLockInfos = array();
         foreach ($aoLocks as $oLock) {
             $nLockType = $oLock->getLockType();
             switch ($nLockType) {
                 case AnwLock::TYPE_PAGEONLY:
                     $sTranslation = "err_ex_lock_details_pageonly";
                     break;
                 case AnwLock::TYPE_PAGEGROUP:
                     $sTranslation = "err_ex_lock_details_pagegroup";
                     break;
                 default:
                     throw new AnwUnexpectedException("lock type unknown");
                     break;
             }
             $asLockInfos[] = self::g_($sTranslation, array("user" => '<b>' . AnwUtils::xText($oLock->getLockUser()->getDisplayName()) . '</b>', "pagename" => '<i>' . AnwUtils::xText($oLock->getLockPage()->getName()) . '</i>', "timestart" => Anwi18n::dateTime($oLock->getLockTime()), "timeseen" => Anwi18n::dateTime($oLock->getLockTimeLast()), "timeexpire" => Anwi18n::dateTime($oLock->getLockTimeLast() + self::globalCfgLocksExpiry())));
         }
         $this->headJs($this->tpl()->errorLock_js());
         $this->out = $this->tpl()->errorLock($asLockInfos);
         $this->output();
     } catch (AnwException $e) {
         $nErrorNumber = false;
         if ($e instanceof AnwAclPhpEditionException) {
             $sTitle = self::g_("err_ex_acl_t");
             $sExplain = self::g_("err_ex_acl_php_p");
             $sImageSrc = AnwUtils::pathImg("warning.gif");
         } else {
             if ($e instanceof AnwAclJsEditionException) {
                 $sTitle = self::g_("err_ex_acl_t");
                 $sExplain = self::g_("err_ex_acl_js_p");
                 $sImageSrc = AnwUtils::pathImg("warning.gif");
             } else {
                 if ($e instanceof AnwAclMinTranslatedPercentException) {
                     $sTitle = self::g_("err_ex_acl_t");
                     $sExplain = self::g_("err_ex_acl_mintranslatedpercent_p", array('percent' => $e->getTranslatedPercent()));
                     $sImageSrc = AnwUtils::pathImg("warning.gif");
                 } else {
                     if ($e instanceof AnwAclException) {
                         $sTitle = self::g_("err_ex_acl_t");
                         if (AnwCurrentSession::isLoggedIn()) {
                             $sExplain = self::g_("err_ex_acl_loggedin_p");
                         } else {
                             $sExplain = self::g_("err_ex_acl_loggedout_p");
                         }
                         $sImageSrc = AnwUtils::pathImg("warning.gif");
                     } else {
                         if ($e instanceof AnwBadCallException) {
                             $sTitle = self::g_("err_ex_badcall_t");
                             $sExplain = self::g_("err_ex_badcall_p");
                             $sImageSrc = AnwUtils::pathImg("warning.gif");
                         } else {
                             if ($e instanceof AnwDbConnectException) {
                                 $sTitle = self::g_("err_ex_dbconnect_t");
                                 $sExplain = self::g_("err_ex_dbconnect_p");
                                 $sImageSrc = AnwUtils::pathImg("error.gif");
                                 $nErrorNumber = AnwDebug::reportError($e);
                             } else {
                                 $sTitle = self::g_("err_ex_unexpected_t");
                                 $sExplain = self::g_("err_ex_unexpected_p");
                                 $sImageSrc = AnwUtils::pathImg("error.gif");
                                 $nErrorNumber = AnwDebug::reportError($e);
                             }
                         }
                     }
                 }
             }
         }
         $this->out = $this->tpl()->errorException($sTitle, $sExplain, $sImageSrc, $nErrorNumber);
         //self::output(); //not use $this to avoid potential errors if it's an ActionPage
         $this->output();
     }
 }
 private function saveTranslation()
 {
     try {
         $asAvailableLangs = $this->getoPage()->getPageGroup()->getAvailableLangs();
         //check permissions : translate
         foreach ($asAvailableLangs as $sLang) {
             if (AnwEnv::_POST($this->getChkName($sLang))) {
                 $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), "");
                 if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) {
                     throw new AnwAclException("permission translate denied");
                 }
             }
         }
         $oPageTranslation = null;
         AnwStorage::transactionStart();
         try {
             foreach ($asAvailableLangs as $sLang) {
                 if (AnwEnv::_POST($this->getChkName($sLang))) {
                     $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), "");
                     //create translation
                     $oPageTranslation = $this->getoPage()->createNewTranslation($sTranslationName, $sLang);
                 }
             }
             AnwStorage::transactionCommit();
         } catch (AnwException $e) {
             AnwStorage::transactionRollback();
             throw $e;
         }
         if ($oPageTranslation) {
             // redirect to last created translation
             AnwUtils::redirect(AnwUtils::link($oPageTranslation));
         } else {
             // no translation was created, show form again
             $this->showForm();
         }
     } catch (AnwBadPageNameException $e) {
         $this->showForm($this->g_("err_badpagename"));
     } catch (AnwBadLangException $e) {
         $this->showForm($this->g_("err_badlang"));
     } catch (AnwPageAlreadyExistsException $e) {
         $this->showForm($this->g_("err_pagealreadyexists"));
     } catch (AnwAclException $e) {
         $this->showForm($this->g_("err_nopermission"));
     } catch (AnwLangExistsForPageGroupException $e) {
         $this->showForm($this->g_("err_langexistsforpagegroup"));
     }
 }
示例#17
0
 private function createPageProcess($sLang, $sContentClass)
 {
     $sPageName = $this->getPageName();
     if (!AnwCurrentSession::isActionAllowed($sPageName, 'create', $sLang)) {
         throw new AnwAclException("permission create denied");
     }
     $oContentClass = AnwContentClasses::getContentClass($sContentClass);
     AnwStorage::transactionStart();
     try {
         //create page
         $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sLang);
         //should we create translations for this new page?
         $asAvailableLangs = $oPage->getPageGroup()->getAvailableLangs();
         //check permissions : translate
         foreach ($asAvailableLangs as $sLang) {
             if (AnwEnv::_POST($this->getChkName($sLang))) {
                 $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), "");
                 if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) {
                     throw new AnwAclException("permission translate denied");
                 }
             }
         }
         foreach ($asAvailableLangs as $sLang) {
             if (AnwEnv::_POST($this->getChkName($sLang))) {
                 $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), "");
                 //create translation
                 $oPageTranslation = $oPage->createNewTranslation($sTranslationName, $sLang);
             }
         }
         AnwStorage::transactionCommit();
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
     AnwUtils::redirect(AnwUtils::link($oPage, "edit"));
 }
示例#18
0
 function saveTranslation_onTextValue($oRootNode, $sFieldInput)
 {
     //escape < and >
     $sTranslatedValue = $this->getTranslatedValueFromPost($sFieldInput);
     $bTranslated = (int) AnwEnv::_POST("done-" . $sFieldInput) == 1 ? true : false;
     //deny empty values to avoid unsync
     if (trim($sTranslatedValue) == "") {
         $sTranslatedValue = self::EMPTY_VALUE;
     }
     AnwDebug::log(" --> {$sFieldInput} : " . ($bTranslated ? "TRANSLATED" : "UNTRANSLATED") . " : " . $sTranslatedValue . " ( was " . $oRootNode->nodeValue . ")");
     //$oRootNode->nodeValue = $sTranslatedValue;
     $oRootNode = AnwXml::xmlReplaceTextNodeValue($oRootNode, $sTranslatedValue);
     $oRootNode = AnwXml::xmlSetTextUntranslated($oRootNode, !$bTranslated);
     //xml structure is now modified
 }
示例#19
0
 /**
  * Import selected files.
  *
  */
 private function doImport($sUploadedFile, $asSelectedPages, $bContinueOnErrors)
 {
     // we will display the import result after running the whole import
     // that's why we save the output in a temporary buffer during this process
     $sOutBuffer = "";
     //load XML from file
     $aaData = $this->getDataFromXmlFile(self::tmpFilename($sUploadedFile));
     //delete tmp file
     AnwUtils::unlink(self::tmpFilename($sUploadedFile), ANWPATH_TMP);
     $nCountImportErrors = 0;
     $nCountImportSuccess = 0;
     $bMustRollback = false;
     // only when $bContinueOnErrors = false
     // MAIN TRANSACTION - only when $bContinueOnErrors = false
     if ($bContinueOnErrors) {
         // won't revert whole import if errors
         $bMainTransaction = false;
         // will commit immediately each imported content
         $bSubTransaction = true;
     } else {
         // will revert whole import if errors
         $bMainTransaction = true;
         // won't commit immediately each imported content
         $bSubTransaction = false;
     }
     if ($bMainTransaction) {
         AnwStorage::transactionStart();
     }
     try {
         foreach ($aaData['PAGEGROUPS'] as $aaDataGroup) {
             $sOutBuffer .= $this->tpl()->rowGroupOpen();
             $oFirstPage = null;
             $oContentClass = AnwContentClasses::getContentClass($aaDataGroup['CONTENTCLASS']);
             foreach ($aaDataGroup['PAGES'] as $aaDataPage) {
                 $asNotices = array();
                 $sOriginalPageName = $aaDataPage['NAME'];
                 $sPageName = AnwEnv::_POST($this->getInputPageName($sOriginalPageName));
                 $sPageLang = AnwEnv::_POST($this->getInputPageLang($sOriginalPageName));
                 if (!$sPageName || !$sPageLang) {
                     throw new AnwUnexpectedException("PageName or PageLang not found for imported content: " . $sOriginalPageName);
                 }
                 $sPageContent = $aaDataPage['CONTENT'];
                 //do we want to import this page?
                 if (in_array($sOriginalPageName, $asSelectedPages) && $sPageName && $sPageLang) {
                     //check pagename and content
                     $asNotices = $this->checkPermissions($sPageName, $sPageLang, $sPageContent);
                     if (count($asNotices) == 0) {
                         // SUB TRANSACTION - only when $bContinueOnErrors = true
                         if ($bSubTransaction) {
                             AnwStorage::transactionStart();
                         }
                         try {
                             // create the new page
                             $oContent = $oContentClass->rebuildContentFromXml($sPageContent);
                             if (!$oFirstPage) {
                                 $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, "", $oContent);
                             } else {
                                 $oPage = $oFirstPage->createNewTranslation($sPageName, $sPageLang, "", $oContent);
                             }
                             if ($bSubTransaction) {
                                 AnwStorage::transactionCommit();
                             }
                             // wait for everything to be completed before affecting $oFirstPage, in case of it fails
                             if (!$oFirstPage) {
                                 $oFirstPage = $oPage;
                             }
                         } catch (AnwException $e) {
                             // special errors management, see FS#62
                             $asNotices[] = $this->t_("notice_unknown") . " (" . $e->getMessage() . ")";
                             //print $e->getFile().'!'.$e->getLine();print_r($e->getTrace());
                             if ($bMainTransaction) {
                                 // we will have to rollback, but we still continue to get the whole report
                                 $bMustRollback = true;
                             }
                             if ($bSubTransaction) {
                                 AnwStorage::transactionRollback();
                             }
                             AnwDebug::reportError($e);
                         }
                     }
                     // import result
                     if (count($asNotices) == 0) {
                         $nCountImportSuccess++;
                         // at least we got a success!
                         $sOutBuffer .= $this->tpl()->rowTranslationProcess_success($oPage->link());
                     } else {
                         $nCountImportErrors++;
                         $sOutBuffer .= $this->tpl()->rowTranslationProcess_failed($sPageName, $sPageLang, $asNotices);
                     }
                 } else {
                     $sOutBuffer .= $this->tpl()->rowTranslationProcess_skipped($sPageName, $sPageLang);
                 }
             }
             $sOutBuffer .= $this->tpl()->rowGroupClose();
         }
         if ($bMainTransaction) {
             if (!$bMustRollback) {
                 AnwStorage::transactionCommit();
             } else {
                 AnwStorage::transactionRollback();
             }
         }
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
     // output, with import results before the detailled report
     $this->out .= $this->tpl()->beginProcess();
     if ($nCountImportErrors > 0) {
         if ($nCountImportSuccess > 0) {
             if ($bContinueOnErrors) {
                 $this->out .= $this->tpl()->importResultErrorsContinued($nCountImportSuccess, $nCountImportErrors);
             } else {
                 $this->out .= $this->tpl()->importResultErrorsCancelled($nCountImportSuccess, $nCountImportErrors);
             }
         } else {
             $this->out .= $this->tpl()->importResultFailed($nCountImportErrors);
         }
     } else {
         $this->out .= $this->tpl()->importResultSuccess($nCountImportSuccess);
     }
     $this->out .= $this->tpl()->importDetails($sOutBuffer);
 }
示例#20
0
 function isPosted()
 {
     return AnwEnv::_POST(self::POSTED_INPUT_NAME);
 }
示例#21
0
 private function saveDuplication()
 {
     $this->out .= $this->tpl()->beginProcessDuplication($this->getoPage()->getName(), $this->getoPage()->getLang());
     $aoTranslations = $this->getoPage()->getPageGroup()->getPages($this->getoPage());
     //which pages should we duplicate?
     $aaPagesForDuplication = array();
     $oPage = $this->getoPage();
     $aaPagesForDuplication[] = array('LANG' => $oPage->getLang(), 'NAME' => AnwEnv::_POST($this->getInputName($oPage), ""), 'CONTENT' => $oPage->getContent()->toXmlString());
     foreach ($aoTranslations as $oTranslation) {
         if (AnwEnv::_POST($this->getChkName($oTranslation))) {
             $aaPagesForDuplication[] = array('LANG' => $oTranslation->getLang(), 'NAME' => AnwEnv::_POST($this->getInputName($oTranslation), ""), 'CONTENT' => $oTranslation->getContent()->toXmlString());
         }
     }
     AnwStorage::transactionStart();
     try {
         $oFirstPage = null;
         $oContentClass = $this->getoPage()->getPageGroup()->getContentClass();
         //duplicate each page
         foreach ($aaPagesForDuplication as $asPageForDuplication) {
             $asNotices = array();
             $sPageName = $asPageForDuplication['NAME'];
             $sPageLang = $asPageForDuplication['LANG'];
             $sPageContent = $asPageForDuplication['CONTENT'];
             $asNotices = $this->checkPermissions($sPageName, $sPageLang, $sPageContent);
             if (count($asNotices) == 0) {
                 $oContent = $oContentClass->rebuildContentFromXml($sPageContent);
                 if (!$oFirstPage) {
                     $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, "", $oContent);
                     $oFirstPage = $oPage;
                 } else {
                     $oPage = $oFirstPage->createNewTranslation($sPageName, $sPageLang, "", $oContent);
                 }
                 $this->out .= $this->tpl()->rowProcessDuplication_success($oPage->link());
             } else {
                 $this->out .= $this->tpl()->rowProcessDuplication_failed($sPageName, $sPageLang, $asNotices);
             }
         }
         AnwStorage::transactionCommit();
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
     $this->out .= $this->tpl()->endProcessDuplication();
 }
 private function saveTranslations($sAddLang)
 {
     try {
         if (!Anwi18n::langExists($sAddLang)) {
             throw new AnwBadLangException();
         }
         $this->out .= $this->tpl()->startProcess();
         $bSomethingDone = false;
         $aoPageGroups = AnwStorage::getPageGroups(false, null, null);
         AnwStorage::transactionStart();
         try {
             foreach ($aoPageGroups as $oPageGroup) {
                 $aoPages = $oPageGroup->getPages();
                 $bChecked = AnwEnv::_POST($this->getChkName($oPageGroup));
                 if (!isset($aoPages[$sAddLang]) && $bChecked) {
                     $sTranslationName = AnwEnv::_POST($this->getInputName($oPageGroup));
                     //check permissions : translate
                     if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sAddLang)) {
                         throw new AnwAclException("permission translate denied");
                     }
                     //find PageRef
                     $nPageRefId = (int) AnwEnv::_POST($this->getInputRef($oPageGroup));
                     $oPageRef = new AnwPageById($nPageRefId);
                     if (isset($aoPages[$oPageRef->getLang()]) && $oPageRef->getId() == $aoPages[$oPageRef->getLang()]->getId()) {
                         //create translation
                         $oPageTranslation = $oPageRef->createNewTranslation($sTranslationName, $sAddLang);
                         $this->out .= $this->tpl()->newTranslationCreated($sAddLang, $oPageTranslation->link());
                         $bSomethingDone = true;
                     }
                 }
             }
             AnwStorage::transactionCommit();
         } catch (AnwException $e) {
             AnwStorage::transactionRollback();
             throw $e;
         }
         $sUrlContinue = $this->linkMe(array("addlang" => $sAddLang));
         if (!$bSomethingDone) {
             AnwUtils::redirect($sUrlContinue);
         }
         $this->out .= $this->tpl()->endProcess($sUrlContinue);
     } catch (AnwBadPageNameException $e) {
         $this->showForm($sAddLang, $this->g_("err_badpagename"));
     } catch (AnwBadLangException $e) {
         $this->showForm($sAddLang, $this->g_("err_badlang"));
     } catch (AnwPageAlreadyExistsException $e) {
         $this->showForm($sAddLang, $this->g_("err_pagealreadyexists"));
     } catch (AnwAclException $e) {
         $this->showForm($sAddLang, $this->g_("err_nopermission"));
     } catch (AnwLangExistsForPageGroupException $e) {
         $this->showForm($sAddLang, $this->g_("err_langexistsforpagegroup"));
     }
 }