Esempio n. 1
0
    /**
     * Gets an blog list based on the given parameters.
     *
     * @param array $p_parameters
     *    An array of ComparisonOperation objects
     * @param string $p_order
     *    An array of columns and directions to order by
     * @param integer $p_start
     *    The record number to start the list
     * @param integer $p_limit
     *    The offset. How many records from $p_start will be retrieved.
     *
     * @return array $issuesList
     *    An array of Issue objects
     */
    public static function GetList($p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count)
    {
        global $g_ado_db;

        if (!is_array($p_parameters)) {
            return null;
        }

        // adodb::selectLimit() interpretes -1 as unlimited
        if ($p_limit == 0) {
            $p_limit = -1;
        }

        $selectClauseObj = new SQLSelectClause();

        // sets the where conditions
        foreach ($p_parameters as $param) {
            $comparisonOperation = self::ProcessListParameters($param);
            $leftOperand = strtolower($comparisonOperation['left']);

            if ($leftOperand == 'matchalltopics') {
                // set the matchAllTopics flag
                $matchAllTopics = true;

            } elseif ($leftOperand == 'topic') {
                // add the topic to the list of match/do not match topics depending
                // on the operator
                if ($comparisonOperation['symbol'] == '=') {
                    $hasTopics[] = $comparisonOperation['right'];
                } else {
                    $hasNotTopics[] = $comparisonOperation['right'];
                }
            } else {
                $comparisonOperation = self::ProcessListParameters($param);
                if (empty($comparisonOperation)) {
                    continue;
                }

                $whereCondition = $comparisonOperation['left'] . ' '
                . $comparisonOperation['symbol'] . " '"
                . $g_ado_db->escape($comparisonOperation['right']) . "' ";
                $selectClauseObj->addWhere($whereCondition);
            }
        }

        if (count($hasTopics) > 0) {
            if ($matchAllTopics) {
                foreach ($hasTopics as $topicId) {
                    $sqlQuery = self::BuildTopicSelectClause(array($topicId));
                    $whereCondition = "plugin_blog_blog.blog_id IN (\n$sqlQuery        )";
                    $selectClauseObj->addWhere($whereCondition);
                }
            } else {
                $sqlQuery = self::BuildTopicSelectClause($hasTopics);
                $whereCondition = "plugin_blog_blog.blog_id IN (\n$sqlQuery        )";
                $selectClauseObj->addWhere($whereCondition);
            }
        }
        if (count($hasNotTopics) > 0) {
            $sqlQuery = self::BuildTopicSelectClause($hasNotTopics, true);
            $whereCondition = "plugin_blog_blog.blog_id IN (\n$sqlQuery        )";
            $selectClauseObj->addWhere($whereCondition);
        }


        // sets the columns to be fetched
        $tmpBlog = new Blog();
		$columnNames = $tmpBlog->getColumnNames(true);
        foreach ($columnNames as $columnName) {
            $selectClauseObj->addColumn($columnName);
        }

        // sets the main table for the query
        $mainTblName = $tmpBlog->getDbTableName();
        $selectClauseObj->setTable($mainTblName);
        unset($tmpBlog);

        if (is_array($p_order)) {
            $order = self::ProcessListOrder($p_order);
            // sets the order condition if any
            foreach ($order as $orderField=>$orderDirection) {
                $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
            }
        }

        $sqlQuery = $selectClauseObj->buildQuery();

        // count all available results
        $countRes = $g_ado_db->Execute($sqlQuery);
        $p_count = $countRes->recordCount();

        //get tlimited rows
        $blogRes = $g_ado_db->SelectLimit($sqlQuery, $p_limit, $p_start);

        // builds the array of blog objects
        $blogsList = array();
        while ($blog = $blogRes->FetchRow()) {
            $blogObj = new Blog($blog['blog_id']);
            if ($blogObj->exists()) {
                $blogsList[] = $blogObj;
            }
        }

        return $blogsList;
    } // fn GetList
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {     
        $Blog = new Blog($this->m_properties['blog_id']);   
        
        if (!$Blog->exists()) {
                $this->m_error = new PEAR_Error('None or invalid blog was given.', ACTION_BLOGENTRY_ERR_INVALID_BLOG);
                return false;
        }
        
        /*
        if (!$p_context->user->defined) {
            $this->m_error = new PEAR_Error('User must be logged in to add interview question.', ACTION_INTERVIEWITEM_ERR_NO_USER);
            return false;   
        }
        */
               
        if ($this->m_blogentry->exists()) {
            /*
            // to edit existing blogentry, check privileges 
            $MetaInterview = new MetaInterview($this->m_blogentry->getProperty('fk_interview_id'));
            
            $is_admin = $MetaInterview->isUserAdmin($p_context);
            $is_moderator = $MetaInterview->isUserModerator($p_context);
            $is_guest = $MetaInterview->isUserGuest($p_context);
            
            if (!$is_admin && !$is_moderator && !$is_guest) {
                return false;    
            }
            
            if ($is_guest) {
                # have to answer, change status automatically
                if (!strlen($this->m_properties['answer'])) {
                    $this->m_error = new PEAR_Error('An answer was not given.', ACTION_INTERVIEWITEM_ERR_NO_ANSWER);
                    return false;
                }
                $this->m_blogentry->setProperty('answer', $this->m_properties['answer']);
                $this->m_blogentry->setProperty('status', 'date');
            }
            
            if ($is_moderator) {
                if (isset($this->m_properties['question'])) {    
                    $this->m_blogentry->setProperty('question', $this->m_properties['question']);
                }
                
                if (isset($this->m_properties['answer'])) {    
                    $this->m_blogentry->setProperty('answer', $this->m_properties['answer']);
                }    
    
                if (isset($this->m_properties['status']) && ($is_admin || $is_moderator)) {    
                    $this->m_blogentry->setProperty('status', $this->m_properties['status']);
                }  
            }
            
            if ($is_admin) {
                if (isset($this->m_properties['question'])) {    
                    $this->m_blogentry->setProperty('question', $this->m_properties['question']);
                }
                
                if (isset($this->m_properties['answer'])) {    
                    $this->m_blogentry->setProperty('answer', $this->m_properties['answer']);
                }    
    
                if (isset($this->m_properties['status']) && ($is_admin || $is_moderator)) {    
                    $this->m_blogentry->setProperty('status', $this->m_properties['status']);
                }
            }
            
            $this->m_error = ACTION_OK;
            return true;
            */
        } else {
            // create new blogentry

            if (!strlen($this->m_properties['title'])) {
                $this->m_error = new PEAR_Error('No entry title was given.', ACTION_BLOGENTRY_ERR_NO_TITLE);
                return false;
            }
            
            if (!strlen($this->m_properties['content'])) {
                $this->m_error = new PEAR_Error('No entry was given.', ACTION_BLOGENTRY_ERR_NO_CONTENT);
                return false;
            }
            
            if ($this->m_blogentry->create($Blog->getId(), 
                                           $p_context->user->identifier, 
                                           $this->m_properties['title'], 
                                           $this->m_properties['content'],
                                           null, 
                                           $this->m_properties['mood_id'])) {
                //$_REQUEST['f_blogentry_id'] = $this->m_blogentry->identifier;
                $this->m_error = ACTION_OK;
                return true;   
            }   
            
        }
        return false;
    }
Esempio n. 3
0
    camp_html_add_msg(getGS('Blog saved.'), 'ok');
    ?>
    <script language="javascript">
        window.opener.location.reload();
        window.close();
    </script>
    <?php
    exit();
}

?>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Expires" content="now">
	<link rel="stylesheet" type="text/css" href="<?php echo $Campsite['WEBSITE_URL']; ?>/admin-style/admin_stylesheet.css">
	<title><?php $Blog->exists() ? putGS('Edit Blog') : putGS('Add new Blog'); ?></title>
	<?php include_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/javascript_common.php"); ?>
	<style type="text/css">@import url(<?php echo $Campsite["WEBSITE_URL"]; ?>/javascript/jscalendar/calendar-system.css);</style>
    <script type="text/javascript" src="<?php echo $Campsite["WEBSITE_URL"]; ?>/javascript/jscalendar/calendar.js"></script>
    <script type="text/javascript" src="<?php echo $Campsite["WEBSITE_URL"]; ?>/javascript/jscalendar/lang/calendar-<?php echo camp_session_get('TOL_Language', 'en'); ?>.js"></script>
    <script type="text/javascript" src="<?php echo $Campsite["WEBSITE_URL"]; ?>/javascript/jscalendar/calendar-setup.js"></script>

    <script src="<?php echo $Campsite['WEBSITE_URL']; ?>/javascript/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>

<?php camp_html_display_msgs(); ?>

<table style="margin-top: 10px; margin-left: 15px; margin-right: 15px;" cellpadding="0" cellspacing="0" width="95%" class="table_input">
<tr>
  <td style="padding: 3px";>