Example #1
0
    /**
     * This is the Ajax function that is called with the results of the
     * form supplied by news_ajax_modify() to update a current item
     * The following parameters are received in an array 'story'!
     *
     * @param int 'sid' the id of the item to be updated
     * @param string 'title' the title of the news item
     * @param string 'urltitle' the title of the news item formatted for the url
     * @param string 'language' the language of the news item
     * @param string 'bodytext' the summary text of the news item
     * @param int 'bodytextcontenttype' the content type of the summary text
     * @param string 'extendedtext' the body text of the news item
     * @param int 'extendedtextcontenttype' the content type of the body text
     * @param string 'notes' any administrator notes
     * @param int 'published_status' the published status of the item
     * @param int 'displayonindex' display the article on the index page
     * @param string 'action' the action to perform, either 'update', 'delete' or 'pending'
     * @author Mark West
     * @author Frank Schummertz
     * @return array(output, action) with output being a rendered template or a simple text and action the performed action
     */
    public function update()
    {
        $this->checkAjaxToken();
        $story = $this->request->getPost()->get('story');
        $action = $this->request->getPost()->get('action');
        $page = (int) $this->request->getPost()->get('page', 1);

        // Get the current news article
        $item = ModUtil::apiFunc('News', 'User', 'get', array('sid' => $story['sid']));
        if ($item == false || !$action) {
            throw new Zikula_Exception_NotFound($this->__('Error! No such article found.'));
        }

        $output = $action;
        $oldurltitle = $item['urltitle'];

        switch ($action)
        {
            case 'update':
                $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', $item['cr_uid'] . '::' . $item['sid'], ACCESS_EDIT), LogUtil::getErrorMsgPermission());
                // Update the story
                
                // TODO: See Admin Controller on usage of News_ImageUtil::
                // to accomplish the code that has been removed from here to
                // accomodate images

                if (ModUtil::apiFunc('News', 'admin', 'update',
                                array('sid' => $story['sid'],
                                    'title' => $story['title'],
                                    'urltitle' => $story['urltitle'],
                                    '__CATEGORIES__' => $story['__CATEGORIES__'],
                                    '__ATTRIBUTES__' => (isset($story['attributes'])) ? News_Util::reformatAttributes($story['attributes']) : null,
                                    'language' => isset($story['language']) ? $story['language'] : '',
                                    'hometext' => $story['hometext'],
                                    'hometextcontenttype' => $story['hometextcontenttype'],
                                    'bodytext' => $story['bodytext'],
                                    'bodytextcontenttype' => $story['bodytextcontenttype'],
                                    'notes' => $story['notes'],
                                    'displayonindex' => isset($story['displayonindex']) ? $story['displayonindex'] : 0,
                                    'allowcomments' => isset($story['allowcomments']) ? $story['allowcomments'] : 0,
                                    'unlimited' => isset($story['unlimited']) ? $story['unlimited'] : null,
                                    'from' => isset($story['from']) ? $story['from'] : null,
                                    'tonolimit' => isset($story['tonolimit']) ? $story['tonolimit'] : null,
                                    'to' => isset($story['to']) ? $story['to'] : null,
                                    'weight' => $story['weight'],
                                    'pictures' => $story['pictures'],
                                    'published_status' => $story['published_status']))) {

                    // Success
                    // reload the news story and ignore the DBUtil SQLCache
                    $item = ModUtil::apiFunc('News', 'User', 'get', array('sid' => $story['sid'], 'SQLcache' => false));

                    if ($item == false) {
                        throw new Zikula_Exception_NotFound($this->__('Error! No such article found.'));
                    }

                    // Explode the news article into an array of seperate pages
                    $allpages = explode('<!--pagebreak-->', $item['bodytext']);

                    // Set the item hometext to be the required page
                    // no arrays start from zero, pages from one
                    $item['bodytext'] = $allpages[$page - 1];
                    $numitems = count($allpages);
                    unset($allpages);

                    // $info is array holding raw information.
                    $info = ModUtil::apiFunc('News', 'User', 'getArticleInfo', $item);

                    // $links is an array holding pure URLs to
                    // specific functions for this article.
                    $links = ModUtil::apiFunc('News', 'User', 'getArticleLinks', $info);

                    // $preformat is an array holding chunks of
                    // preformatted text for this article.
                    $preformat = ModUtil::apiFunc('News', 'User', 'getArticlePreformat',
                                    array('info' => $info,
                                        'links' => $links));

                    Zikula_AbstractController::configureView();
                    $this->view->setCaching(false);

                    // Assign the story info arrays
                    $this->view->assign(array('info' => $info,
                        'links' => $links,
                        'preformat' => $preformat,
                        'page' => $page));
                    // Some vars
                    $modvars = $this->getVars();
                    $this->view->assign('enablecategorization', $modvars['enablecategorization']);
                    $this->view->assign('catimagepath', $modvars['catimagepath']);
                    $this->view->assign('enableajaxedit', $modvars['enableajaxedit']);

                    // Now lets assign the information to create a pager for the review
                    $this->view->assign('pager', array('numitems' => $numitems,
                        'itemsperpage' => 1));

                    // we do not increment the read count!!!
                    // when urltitle has changed, do a reload with the full url and switch to no shorturl usage
                    if (strcmp($oldurltitle, $item['urltitle']) != 0) {
                        $reloadurl = ModUtil::url('News', 'user', 'display', array('sid' => $info['sid'], 'page' => $page), null, null, true, true);
                    } else {
                        $reloadurl = '';
                    }

                    // Return the output that has been generated by this function
                    $output = $this->view->fetch('user/articlecontent.tpl');
                } else {
                    $output = DataUtil::formatForDisplayHTML($this->__('Error! Could not save your changes.'));
                }
                break;

            case 'pending':
                // Security check
                $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', "{$item['cr_uid']}::{$story['sid']}", ACCESS_EDIT));

                // set published_status to 2 to make the story a pending story
                $object = array('published_status' => 2,
                    'sid' => $story['sid']);

                if (DBUtil::updateObject($object, 'news', '', 'sid') == false) {
                    $output = DataUtil::formatForDisplayHTML($this->__('Error! Could not save your changes.'));
                } else {
                    // Success
                    // the url for reloading, after setting to pending refer to the news index since this article is not visible any more
                    $reloadurl = ModUtil::url('News', 'user', 'view', array(), null, null, true);
                    $output = DataUtil::formatForDisplayHTML($this->__f('Done! Saved your changes.'));
                }
                break;

            case 'delete':
                // Security check inside of the API func
                if (ModUtil::apiFunc('News', 'Admin', 'delete', array('sid' => $story['sid']))) {
                    // Success
                    // the url for reloading, after deleting refer to the news index
                    $reloadurl = ModUtil::url('News', 'user', 'view', array(), null, null, true);
                    $output = DataUtil::formatForDisplayHTML($this->__f('Done! Deleted article.'));
                } else {
                    $output = DataUtil::formatForDisplayHTML($this->__('Error! Could not delete article.'));
                }
                break;

            default:
        }

        // release pagelock
        if (ModUtil::available('PageLock')) {
            ModUtil::apiFunc('PageLock', 'user', 'releaseLock',
                            array('lockName' => "Newsnews{$story['sid']}"));
        }

        // clear article and view caches
        ModUtil::apiFunc('News', 'user', 'clearItemCache', $story);

        return new Zikula_Response_Ajax(array('result' => $output,
            'action' => $action,
            'reloadurl' => $reloadurl));
    }
Example #2
0
 /**
  * Return a newly created pormRender instance with the given name.
  *
  * @param string                    $name       Module name.
  * @param Zikula_AbstractController $controller Controller.
  * @param string                    $className  Optionally instanciate a child of Zikula_Form_View.
  *
  * @return Form_View The newly created Form_View instance.
  */
 public static function newForm($name, Zikula_AbstractController $controller = null, $className = null)
 {
     $container = $controller->getContainer();
     if ($className && !class_exists($className)) {
         throw new RuntimeException(__f('%s does not exist', $className));
     }
     $form = $className ? new $className($container, $name) : new Zikula_Form_View($container, $name);
     if ($className && !$form instanceof Zikula_Form_View) {
         throw new RuntimeException(__f('%s is not an instance of Zikula_Form_View', $className));
     }
     $form->setEntityManager($controller->getEntityManager());
     if ($controller) {
         $form->setController($controller);
         $form->assign('controller', $controller);
     } else {
         LogUtil::log(__('FormUtil::newForm should also include the Zikula_AbstractController as the second argument to enable hooks to work.'), Zikula_AbstractErrorHandler::NOTICE);
     }
     return $form;
 }
Example #3
0
 public function deletedialog()
 {
     $this->checkAjaxToken();
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', ACCESS_DELETE));
     $cid = $this->request->getPost()->get('cid');
     $allCats = CategoryUtil::getSubCategories(1, true, true, true, false, true, $cid);
     $selector = CategoryUtil::getSelector_Categories($allCats);
     Zikula_AbstractController::configureView();
     $this->view->setCaching(Zikula_View::CACHE_DISABLED);
     $this->view->assign('categorySelector', $selector);
     $result = array('result' => $this->view->fetch('categories_adminajax_delete.tpl'));
     return new Zikula_Response_Ajax($result);
 }
Example #4
0
 /**
  * Constructor.
  *
  * @param Zikula_ServiceManager $serviceManager ServiceManager.
  * @param Zikula_AbstractPlugin $plugin         Plugin.
  * @param array                 $options        Options.
  */
 public function __construct(Zikula_ServiceManager $serviceManager, Zikula_AbstractPlugin $plugin, array $options = array())
 {
     $this->plugin = $plugin;
     parent::__construct($serviceManager, $options);
 }
Example #5
0
    /**
     *   Revisió de l'existència dels centres introduïts
     *   
     * @return Zikula_Response_Ajax
     * @throws Zikula_Exception_Fatal
     */
    public function checkCentres() {
        if (!SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_READ)) {
            throw new Zikula_Exception_Fatal($this->__('No teniu autorització per accedir a aquest mòdul.'));
        }

        $centres = $this->request->getPost()->get('centres', '');

        if ($centres) {
            $c = str_replace(" ", "", $centres); // Treiem caràcters en blanc
            // Processar codis dels centres per verificar existència
            $nomsCentres = ModUtil::apiFunc($this->name, 'user', 'checkCentres', array('centres' => $c));

            Zikula_AbstractController::configureView();
            $view = Zikula_View::getInstance('Cataleg', false);
            $view->assign('nomsCentres', $nomsCentres);
            $content = $view->fetch('user/Cataleg_user_centres.tpl');
            $codis = $nomsCentres['codis'];
        }
        return new Zikula_Response_Ajax(array('codis_ori' => $c, // Els codis introduïts a la plantilla
                    'codis' => $nomsCentres['codis'], // Els codis de centre vàlids
                    'content' => $content));
    }
Example #6
0
 /**
  * Return a newly created Zikula Form instance with the given name.
  *
  * @param string                    $name       Module or plugin name.
  * @param Zikula_AbstractController $controller Controller.
  * @param string                    $className  Optionally instanciate a child of Zikula_Form_View.
  *
  * @return Zikula_Form_View The newly created Form_View instance.
  */
 public static function newForm($name, Zikula_AbstractController $controller = null, $className = null)
 {
     $serviceManager = $controller->getContainer();
     if ($className && !class_exists($className)) {
         throw new RuntimeException(__f('%s does not exist', $className));
     }
     if ($controller instanceof Zikula_Controller_AbstractPlugin) {
         // for plugins get module name from controller
         $modinfo = $controller->getModInfo();
         $form = $className ? new $className($serviceManager, $modinfo['name'], $name) : new Zikula_Form_View_Plugin($serviceManager, $modinfo['name'], $name);
     } else {
         $form = $className ? new $className($serviceManager, $name) : new Zikula_Form_View($serviceManager, $name);
     }
     if ($className && !$form instanceof Zikula_Form_View) {
         throw new RuntimeException(__f('%s is not an instance of Zikula_Form_View', $className));
     }
     $form->setEntityManager($controller->getEntityManager());
     if ($controller) {
         $form->setController($controller);
         $form->assign('controller', $controller);
     } else {
         LogUtil::log(__('FormUtil::newForm should also include the Zikula_AbstractController as the second argument to enable hooks to work.'), \Monolog\Logger::NOTICE);
     }
     return $form;
 }
Example #7
0
    /**
     * Change the users in select list
     *
     * @param array $args Array with the id of the note
     *
     * @return Redirect to the user main page
     */
    public function chgUsers($args) {
        if (!SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_ADMIN)) {
            throw new Zikula_Exception_Fatal($this->__('Sorry! No authorization to access this module.'));
        }

        $gid = $this->request->getPost()->get('gid', '');
        if (!$gid) {
            throw new Zikula_Exception_Fatal($this->__('no group id'));
        }

        // get group members
        $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
        $groupMembers = ModUtil::func('IWmain', 'user', 'getMembersGroup', array('sv' => $sv,
                    'gid' => $gid));
        if ($groupMembers)
            asort($groupMembers);

        if (empty($groupMembers))
            throw new Zikula_Exception_Fatal($this->__('unable to get group members or group is empty for gid=') . DataUtil::formatForDisplay($gid));

        Zikula_AbstractController::configureView();
        $this->view->assign('groupMembers', $groupMembers);
        $this->view->assign('action', 'chgUsers');
        $content = $this->view->fetch('IWagendas_admin_ajax.htm');
        return new Zikula_Response_Ajax(array('content' => $content,
                ));
    }