Example #1
0
 function updateokAction()
 {
     global $xoopsUser, $xoopsModuleConfig;
     require_once XOOPS_ROOT_PATH . '/modules/openid/class/utils.php';
     if (!OpenID_Utils::validateToken()) {
         redirect_header($this->_url, 2, 'Token Error');
     }
     if (!isset($_POST['mode'])) {
         redirect_header($this->_url, 2, 'Bad operation.');
     }
     $ids = array_keys($_POST['mode']);
     $identifiers =& $this->_handler->get4Update($xoopsUser->getVar('uid'), $ids);
     $success = 0;
     $errors = '';
     foreach ($identifiers as $identifier) {
         $changed = false;
         $id = $identifier->get('id');
         $oldmode = intval($identifier->get('omode'));
         $mode = intval($_POST['mode'][$id]);
         if ($xoopsModuleConfig['mode_policy'] == 0) {
             if ($mode != $oldmode) {
                 $identifier->set('omode', $mode);
                 $changed = true;
             }
         } else {
             if ($oldmode == OPENID_IDENTIFIER_INACTIVE) {
                 if ($mode == OPENID_IDENTIFIER_ACTIVE) {
                     $identifier->set('omode', $xoopsModuleConfig['mode_policy']);
                     $changed = true;
                 }
             } else {
                 if ($mode == OPENID_IDENTIFIER_INACTIVE) {
                     $identifier->set('omode', OPENID_IDENTIFIER_INACTIVE);
                     $changed = true;
                 } else {
                     if ($oldmode != $xoopsModuleConfig['mode_policy']) {
                         $identifier->set('omode', $xoopsModuleConfig['mode_policy']);
                         $changed = true;
                     }
                 }
             }
         }
         if ($changed) {
             if ($this->_handler->update($identifier)) {
                 $success++;
             } else {
                 $errors .= $this->_handler->getError() . '<br />';
             }
         }
     }
     if ($success > 0) {
         $message = $success . ' records are updated.';
     } else {
         $message = 'OpenID was not updated.';
     }
     if ($errors != '') {
         $message .= '<br />' . $errors;
     }
     redirect_header($this->_url, 2, $message);
 }