* @author Jess Martin */ /** * ItemEditOption for adding password protection to an item or album * * @package Password * @subpackage UserInterface */ class PasswordOption extends ItemEditOption { /** * @see ItemEditOption::isAppropriate */ function isAppropriate($item, $thumbnail) { list ($ret, $canChange) = GalleryCoreApi::hasItemPermission($item->getId(), 'core.changePermissions'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } return array(null, $canChange); } /** * @see ItemEditOption::loadTemplate */ function loadTemplate(&$template, &$form, $item, $thumbnail) { $form['PasswordOption']['hasPassword'] = $item->hasOnLoadHandler('Password'); $form['PasswordOption']['isAlbum'] = $item->getCanContainChildren(); return array(null, 'modules/password/templates/PasswordOption.tpl', 'modules_password'); } /** * @see ItemEditOption::handleRequestAfterEdit */ function handleRequestAfterEdit($form, &$item, &$preferred) { $error = $warning = array(); $ret = GalleryCoreApi::assertHasItemPermission($item->getId(), 'core.changePermissions'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } if (isset($form['PasswordOption']['remove']) && $form['PasswordOption']['remove']) { GalleryCoreApi::requireOnce('modules/password/classes/PasswordHelper.class'); $ret = PasswordHelper::removePassword($item); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } } else if (!empty($form['PasswordOption']['password1']) || !empty($form['PasswordOption']['password2'])) { if ($form['PasswordOption']['password1'] == $form['PasswordOption']['password2']) { GalleryCoreApi::requireOnce('modules/password/classes/PasswordHelper.class'); $ret = PasswordHelper::setPassword($item, GalleryUtilities::htmlEntityDecode($form['PasswordOption']['password1'])); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } } else { /* Throw an error because both passwords do not match */ $error[] = 'form[error][PasswordOption][mismatch]'; } } return array(null, $error, $warning); } } ?>