Example #1
0
 /**
  *
  */
 public function SaveCommentTagging()
 {
     # --- inline is passed to indicate form appears embedded in detail page, not in overlay
     $vn_inline_form = $this->request->getParameter("inline", pInteger);
     if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->request->getParameter("tablename", pString), true))) {
         die("Invalid table name " . $this->request->getParameter("tablename", pString) . " for saving comment");
     }
     $ps_table = $this->request->getParameter("tablename", pString);
     if (!($vn_item_id = $this->request->getParameter("item_id", pInteger))) {
         if ($vn_inline_form) {
             $this->notification->addNotification(_t("Invalid ID"), __NOTIFICATION_TYPE_ERROR__);
             $this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
         } else {
             $this->view->setVar("message", _t("Invalid ID"));
             $this->render("Form/reload_html.php");
         }
         return;
     }
     if (!$t_item->load($vn_item_id)) {
         if ($vn_inline_form) {
             $this->notification->addNotification(_t("ID does not exist"), __NOTIFICATION_TYPE_ERROR__);
             $this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
         } else {
             $this->view->setVar("message", _t("ID does not exist"));
             $this->render("Form/reload_html.php");
         }
         return;
     }
     # --- get params from form
     $ps_comment = $this->request->getParameter('comment', pString);
     $pn_rank = $this->request->getParameter('rank', pInteger);
     $ps_tags = $this->request->getParameter('tags', pString);
     $ps_email = $this->request->getParameter('email', pString);
     $ps_name = $this->request->getParameter('name', pString);
     $ps_location = $this->request->getParameter('location', pString);
     $ps_media1 = $_FILES['media1']['tmp_name'];
     $ps_media1_original_name = $_FILES['media1']['name'];
     $va_errors = array();
     if (!$this->request->getUserID() && !$ps_name && !$ps_email) {
         $va_errors["general"] = _t("Please enter your name and email");
     }
     if (!$ps_comment && !$pn_rank && !$ps_tags && !$ps_media1) {
         $va_errors["general"] = _t("Please enter your contribution");
     }
     if (sizeof($va_errors)) {
         $this->view->setVar("form_comment", $ps_comment);
         $this->view->setVar("form_rank", $pn_rank);
         $this->view->setVar("form_tags", $ps_tags);
         $this->view->setVar("form_email", $ps_email);
         $this->view->setVar("form_name", $ps_name);
         $this->view->setVar("form_location", $ps_location);
         $this->view->setVar("item_id", $vn_item_id);
         $this->view->setVar("tablename", $ps_table);
         if ($vn_inline_form) {
             $this->notification->addNotification($va_errors["general"], __NOTIFICATION_TYPE_ERROR__);
             $this->request->setActionExtra($vn_item_id);
             $this->__call(caGetDetailForType($ps_table), null);
             #$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
         } else {
             $this->view->setVar("errors", $va_errors);
             $this->render('Details/form_comments_html.php');
         }
     } else {
         if (!($pn_rank > 0 && $pn_rank <= 5)) {
             $pn_rank = null;
         }
         if ($ps_comment || $pn_rank || $ps_media1) {
             $t_item->addComment($ps_comment, $pn_rank, $this->request->getUserID(), null, $ps_name, $ps_email, $this->request->config->get("dont_moderate_comments") ? 1 : 0, null, array('media1_original_filename' => $ps_media1_original_name), $ps_media1, null, null, null, $ps_location);
         }
         if ($ps_tags) {
             $va_tags = array();
             $va_tags = explode(",", $ps_tags);
             foreach ($va_tags as $vs_tag) {
                 $t_item->addTag(trim($vs_tag), $this->request->getUserID(), null, $this->request->config->get("dont_moderate_comments") ? 1 : 0, null);
             }
         }
         if ($ps_comment || $ps_tags || $ps_media1) {
             # --- check if email notification should be sent to admin
             if (!$this->request->config->get("dont_email_notification_for_new_comments")) {
                 # --- send email confirmation
                 $o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
                 $o_view->setVar("comment", $ps_comment);
                 $o_view->setVar("tags", $ps_tags);
                 $o_view->setVar("name", $ps_name);
                 $o_view->setVar("email", $ps_email);
                 $o_view->setVar("item", $t_item);
                 # -- generate email subject line from template
                 $vs_subject_line = $o_view->render("mailTemplates/admin_comment_notification_subject.tpl");
                 # -- generate mail text from template - get both the text and the html versions
                 $vs_mail_message_text = $o_view->render("mailTemplates/admin_comment_notification.tpl");
                 $vs_mail_message_html = $o_view->render("mailTemplates/admin_comment_notification_html.tpl");
                 caSendmail($this->request->config->get("ca_admin_email"), $this->request->config->get("ca_admin_email"), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
             }
             if ($this->request->config->get("dont_moderate_comments")) {
                 if ($vn_inline_form) {
                     $this->notification->addNotification(_t("Thank you for contributing."), __NOTIFICATION_TYPE_INFO__);
                     $this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
                     return;
                 } else {
                     $this->view->setVar("message", _t("Thank you for contributing."));
                     $this->render("Form/reload_html.php");
                 }
             } else {
                 if ($vn_inline_form) {
                     $this->notification->addNotification(_t("Thank you for contributing.  Your comments will be posted on this page after review by site staff."), __NOTIFICATION_TYPE_INFO__);
                     $this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
                     return;
                 } else {
                     $this->view->setVar("message", _t("Thank you for contributing.  Your comments will be posted on this page after review by site staff."));
                     $this->render("Form/reload_html.php");
                 }
             }
         } else {
             if ($vn_inline_form) {
                 $this->notification->addNotification(_t("Thank you for your contribution."), __NOTIFICATION_TYPE_INFO__);
                 $this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
                 return;
             } else {
                 $this->view->setVar("message", _t("Thank you for your contribution."));
                 $this->render("Form/reload_html.php");
             }
         }
     }
 }
Example #2
0
/**
 * Returns url to display a detail for an item. 
 *
 * @param HTTPRequest $po_request The current request object
 * @param string $ps_table The name or table_num of the edited items table
 * @param int $pn_id Optional row_id for edited item. If omitted a link will be returned to create a new item record. Note that unless the verifyLink option is set, the link will be returned with the specified id whether or not it actually exists.
 * @param boolean $pb_return_url_as_pieces If true an array is returned with the various components of the editor URL as separate keys. The keys will be 'module', 'controller', 'action' and '_pk' (the name of the primary key for the item); the primary key value itself is returned as both 'id' and whatever the primary key name is (eg. named whatever the value of _pk is). Default is false - return as a string rather than array.
 * @param array $pa_additional_parameters Optional array of parameters to return on the editor url
 * @param array $pa_options Optional array of options. Supported options are:
 * 		verifyLink = if true and $pn_id is set, then existence of record with specified id is verified before link is returned. If the id does not exist then null is returned. Default is false - no verification performed.
 *		action = if set, action of returned link will be set to the supplied value
 *		type_id = type_id of item to get detail for
 */
function caDetailUrl($po_request, $ps_table, $pn_id = null, $pb_return_url_as_pieces = false, $pa_additional_parameters = null, $pa_options = null)
{
    $o_dm = Datamodel::load();
    if (is_numeric($ps_table)) {
        if (!($t_table = $o_dm->getInstanceByTableNum($ps_table, true))) {
            return null;
        }
    } else {
        if (!($t_table = $o_dm->getInstanceByTableName($ps_table, true))) {
            return null;
        }
    }
    $vs_pk = $t_table->primaryKey();
    $vs_table = $ps_table;
    $vs_module = '';
    $vs_controller = 'Detail';
    if (isset($pa_options['action'])) {
        $vs_action = $pa_options['action'];
    } else {
        $vs_action = caGetDetailForType($ps_table, caGetOption('type_id', $pa_options, null), array('request' => $po_request));
    }
    if (caUseIdentifiersInUrls() && $t_table->getProperty('ID_NUMBERING_ID_FIELD')) {
        $va_ids = $t_table->getFieldValuesForIDs(array($pn_id), array($t_table->getProperty('ID_NUMBERING_ID_FIELD')));
        if (is_array($va_ids) && ($vn_id_for_idno = array_shift($va_ids))) {
            $vb_id_exists = true;
        }
        if (strlen($vn_id_for_idno)) {
            $pn_id = $vn_id_for_idno;
        } else {
            $pn_id = "id:{$pn_id}";
        }
    }
    $vs_action .= "/" . rawurlencode($pn_id);
    if (isset($pa_options['verifyLink']) && $pa_options['verifyLink']) {
        // Make sure record link points to exists
        if (!$vb_id_exists && $pn_id > 0 && !$t_table->load($pn_id)) {
            return null;
        }
    }
    if ($pb_return_url_as_pieces) {
        return array('module' => $vs_module, 'controller' => $vs_controller, 'action' => $vs_action, $vs_pk => $pn_id, 'id' => $pn_id, '_pk' => $vs_pk);
    } else {
        if (!is_array($pa_additional_parameters)) {
            $pa_additional_parameters = array();
        }
        //$pa_additional_parameters = array_merge(array('id' => $pn_id), $pa_additional_parameters);
        return caNavUrl($po_request, $vs_module, $vs_controller, $vs_action, $pa_additional_parameters);
    }
}