/** * Creates the list of objects. Sets the parameter $p_hasNextElements to * true if this list is limited and elements still exist in the original * list (from which this was truncated) after the last element of this * list. * * @param int $p_start * @param int $p_limit * @param bool $p_hasNextElements * @return array */ protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count) { $operator = new Operator('is'); $context = CampTemplate::singleton()->context(); $comparisonOperation = new ComparisonOperation('poll_nr', $operator, $context->poll->number); $this->m_constraints[] = $comparisonOperation; $comparisonOperation = new ComparisonOperation('pollanswer_nr', $operator, $context->pollanswer->number); $this->m_constraints[] = $comparisonOperation; $pollAnswerAttachmentsList = PollAnswerAttachment::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count); $metaPollAnswerAttachmentsList = array(); foreach ($pollAnswerAttachmentsList as $pollAnswerAttachment) { $metaPollAnswerAttachmentsList[] = new MetaAttachment($pollAnswerAttachment->getAttachmentId()); } return $metaPollAnswerAttachmentsList; }
/** * Gets an issue 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_count * The count of answers. * * @return array $pollAnswerAttachmentsList * An array of Attachment objects */ public static function GetList(array $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; } // sets the where conditions foreach ($p_parameters as $param) { $comparisonOperation = self::ProcessListParameters($param); if (empty($comparisonOperation)) { continue; } if (strpos($comparisonOperation['left'], 'poll_nr') !== false) { $poll_nr = $comparisonOperation['right']; } if (strpos($comparisonOperation['left'], 'pollanswer_nr') !== false) { $pollanswer_nr = $comparisonOperation['right']; } } $sqlClauseObj = new SQLSelectClause(); // sets the columns to be fetched $tmpPollAnswerAttachment = new PollAnswerAttachment($language_id, $poll_nr); $columnNames = $tmpPollAnswerAttachment->getColumnNames(true); foreach ($columnNames as $columnName) { $sqlClauseObj->addColumn($columnName); } // sets the main table for the query $mainTblName = $tmpPollAnswerAttachment->getDbTableName(); $sqlClauseObj->setTable($mainTblName); unset($tmpPollAnswerAttachment); if (empty($pollanswer_nr) || empty($poll_nr)) { return; } $sqlClauseObj->addWhere("fk_poll_nr = " . $g_ado_db->escape($poll_nr)); $sqlClauseObj->addWhere("fk_pollanswer_nr = " . $g_ado_db->escape($pollanswer_nr)); if (!is_array($p_order)) { $p_order = array(); } // sets the ORDER BY condition $p_order = count($p_order) > 0 ? $p_order : self::$s_defaultOrder; $order = self::ProcessListOrder($p_order); foreach ($order as $orderColumn => $orderDirection) { $sqlClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection); } $sqlQuery = $sqlClauseObj->buildQuery(); // count all available results $countRes = $g_ado_db->Execute($sqlQuery); $p_count = $countRes->recordCount(); //get the wanted rows $pollAnswerAttachments = $g_ado_db->Execute($sqlQuery); // builds the array of poll objects $pollAnswerAttachmentsList = array(); while ($pollAnswerAttachment = $pollAnswerAttachments->FetchRow()) { $pollAnswerAttachment = new Attachment($pollAnswerAttachment['fk_attachment_id']); if ($pollAnswerAttachment->exists()) { $pollAnswerAttachmentsList[] = $pollAnswerAttachment; } } return $pollAnswerAttachmentsList; }
<?php $PollAnswerAttachments = PollAnswerAttachment::getPollAnswerAttachments($f_poll_nr, $f_pollanswer_nr); ?> <center> <TABLE width="95%" style="border: 1px solid #EEEEEE;"> <TR> <TD> <TABLE width="100%" bgcolor="#EEEEEE" cellpadding="3" cellspacing="0"> <TR> <TD align="left"> <STRONG><?php putGS("Files"); ?></STRONG> </TD> <?php if (($f_edit_mode == "edit") && $g_user->hasPermission('AddFile')) { ?> <TD align="right"> <IMG src="<?php p($Campsite["ADMIN_IMAGE_BASE_URL"]);?>/add.png" border="0"> <A href="javascript: void(0);" onclick="window.open('<?php echo camp_html_article_url($articleObj, $f_language_id, "files/popup.php"); ?>', 'attach_file', 'scrollbars=yes, resizable=yes, menubar=no, toolbar=no, width=500, height=400, top=200, left=100');"><?php putGS("Attach"); ?></A> </TD> <?php } ?> </TR> </TABLE> </TD> </TR> <?php foreach ($PollAnswerAttachments as $PollAnswerAttachment) { $file = $PollAnswerAttachment->getAttachment(); $fileEditUrl = "edit.php?f_publication_id=$f_publication_id&f_issue_number=$f_issue_number&f_section_number=$f_section_number&f_article_number=$f_article_number&f_attachment_id=".$file->getAttachmentId()."&f_language_id=$f_language_id&f_language_selected=$f_language_selected"; $deleteUrl = "do_del.php?f_poll_nr=$f_poll_nr&f_pollanswer_nr=$f_pollanswer_nr&f_fk_language_id=$f_fk_language_id&f_attachment_id=".$file->getAttachmentId().'&'.SecurityToken::URLParameter(); $downloadUrl = "/attachment/".basename($file->getStorageLocation())."?g_download=1"; if (strstr($file->getMimeType(), "image/") && (strstr($_SERVER['HTTP_ACCEPT'], $file->getMimeType()) || (strstr($_SERVER['HTTP_ACCEPT'], "*/*")))) {
$attributes['fk_description_id'] = $description->getPhraseId(); $attributes['fk_user_id'] = $g_user->getUserId(); if ($f_language_specific == "yes") { $attributes['fk_language_id'] = $f_language_id; } if ($f_content_disposition == "attachment") { $attributes['content_disposition'] = "attachment"; } if (!empty($_FILES['f_file'])) { $file = Attachment::OnFileUpload($_FILES['f_file'], $attributes); } else { camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'files/popup.php')); } // Check if image was added successfully if (PEAR::isError($file)) { camp_html_add_msg($file->getMessage()); camp_html_goto_page($BackLink); } $PollAnswerAttachment = new PollAnswerAttachment($f_poll_nr, $f_pollanswer_nr, $file->getAttachmentId()); $PollAnswerAttachment->create(); // Go back to upload screen. camp_html_add_msg(getGS("File '$1' added.", $file->getFileName()), "ok"); ?> <script> location.href="popup.php?f_poll_nr=<?php p($f_poll_nr) ?>&f_pollanswer_nr=<?php p($f_pollanswer_nr) ?>&f_fk_language_id=<?php p($f_fk_language_id) ?>"; </script>
/** * Delete poll from database. This will * only delete one specific translation of the poll question. * * @return boolean */ function delete() { // Delte PollAnswerAttachments PollAnswerAttachment::OnPollAnswerDelete($this->getPollNumber(), $this->getNumber()); // Delete from plugin_poll_answer table $deleted = parent::delete(); /* if ($deleted) { if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logtext = getGS('Article #$1: "$2" ($3) deleted.', $this->m_data['Number'], $this->m_data['Name'], $this->getLanguageName()) ." (".getGS("Publication")." ".$this->m_data['IdPublication'].", " ." ".getGS("Issue")." ".$this->m_data['NrIssue'].", " ." ".getGS("Section")." ".$this->m_data['NrSection'].")"; Log::Message($logtext, null, 32); } */ $CampCache = CampCache::singleton(); $CampCache->clear('user'); return $deleted; } // fn delete
exit; } $f_poll_nr = Input::Get('f_poll_nr', 'int', 0); $f_pollanswer_nr = Input::Get('f_pollanswer_nr', 'int', 0); $f_fk_language_id = Input::Get('f_fk_language_id', 'int', 0); $f_attachment_id = Input::Get('f_attachment_id', 'int', 0); $attachmentObj = new Attachment($f_attachment_id); if (!$attachmentObj->exists()) { camp_html_display_error(getGS('Attachment does not exist.'), null, true); exit; } $filePath = dirname($attachmentObj->getStorageLocation()) . '/' . $attachmentObj->getFileName(); if (!is_writable(dirname($filePath))) { camp_html_add_msg(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $filePath, basename($attachmentObj->getStorageLocation()))); //camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'edit.php')); exit; } $PollAnswerAttachment = new PollAnswerAttachment($f_poll_nr, $f_pollanswer_nr, $f_attachment_id); $PollAnswerAttachment->delete(); // Go back to upload screen. camp_html_add_msg(getGS("File '$1' deleted.", $attachmentObj->getFileName()), "ok"); $attachmentObj->delete(); ?> <script> location.href="popup.php?f_poll_nr=<?php p($f_poll_nr) ?>&f_pollanswer_nr=<?php p($f_pollanswer_nr) ?>&f_fk_language_id=<?php p($f_fk_language_id) ?>"; </script>