function xnppresentationUpdateItem($item_id) { global $xoopsDB; $xnpsid = $_SESSION['XNPSID']; $formdata =& xoonips_getutility('formdata'); $myts =& MyTextSanitizer::getInstance(); // modify BasicInformation, Index, Preview and Attachment. $result = xnpUpdateBasicInformation($item_id); if ($result) { $result = xnpUpdateIndex($item_id); if ($result) { $result = xnpUpdatePreview($item_id); if ($result) { $result = xnpUpdateAttachment($item_id, 'presentation_file'); if ($result) { $result = xnp_insert_change_log($xnpsid, $item_id, $formdata->getValue('post', 'change_log', 's', true)); $result = !$result; if (!$result) { echo ' xnp_insert_change_log failed.'; } } else { echo ' xnpUpdateAttachment failed.'; } } else { echo ' xnpUpdatePreview failed.'; } } else { echo ' xnpUpdateIndex failed.'; } } else { echo ' xnpUpdateBasicInformation failed.'; } if (!$result) { return false; } list($rights, $use_cc, $cc_commercial_use, $cc_modification) = xnpGetRights(); // trim strings $ar = array('presentation_type' => $formdata->getValue('post', 'presentation_type', 's', true), 'readme' => xnpGetTextFile('readme'), 'rights' => $rights); xnpTrimColumn($ar, 'xnppresentation_item_detail', array_keys($ar), _CHARSET); // register detail information $attachment_dl_limit = $formdata->getValue('post', 'attachment_dl_limit', 'i', true); $attachment_dl_notify = $formdata->getValue('post', 'attachment_dl_notify', 'i', true); $sql = implode(',', array('attachment_dl_limit' . '=\'' . $attachment_dl_limit . '\'', 'attachment_dl_notify' . '=\'' . ($attachment_dl_limit ? $attachment_dl_notify : 0) . '\'', 'presentation_type' . '=\'' . addslashes($ar['presentation_type']) . '\'', 'readme' . '=\'' . addslashes($ar['readme']) . '\'', 'rights' . '=\'' . addslashes($ar['rights']) . '\'', 'use_cc' . '=\'' . $use_cc . '\'', 'cc_commercial_use' . '=\'' . $cc_commercial_use . '\'', 'cc_modification' . '=\'' . $cc_modification . '\'')); $result = $xoopsDB->queryF('update ' . $xoopsDB->prefix('xnppresentation_item_detail') . " set {$sql} where presentation_id = {$item_id} "); if ($result == false) { return false; } // insert/update creator $formdata =& xoonips_getutility('formdata'); $creator_handler =& xoonips_getormhandler('xnppresentation', 'creator'); $creator_objs =& $formdata->getObjectArray('post', $creator_handler->getTableName(), $creator_handler, false); if (!$creator_handler->updateAllObjectsByForeignKey('presentation_id', $item_id, $creator_objs)) { return false; } return true; }
function xnpbookUpdateItem($book_id) { // set fixed value for month and day $_POST['publicationDateMonth'] = 1; $_POST['publicationDateDay'] = 1; $formdata =& xoonips_getutility('formdata'); // edit BasicInformation, Index, Preview, Attachment $result = xnpUpdateBasicInformation($book_id); if ($result) { $result = xnpUpdateIndex($book_id); if ($result) { $result = xnpUpdateAttachment($book_id, 'book_pdf'); if ($result) { $result = xnp_insert_change_log($_SESSION['XNPSID'], $book_id, $formdata->getValue('post', 'change_log', 's', false)); $result = !$result; if (!$result) { error_log('xnp_insert_change_log failed.'); } } else { error_log('xnpUpdateAttachment failed.'); } } else { error_log('xnpUpdateIndex failed.'); } } else { error_log('xnpUpdateBasicInformation failed.'); } if (!$result) { return false; } // limit length $ar = _xnpbook_get_detail_request(); xnpTrimColumn($ar, 'xnpbook_item_detail', array_keys($ar), _CHARSET); $hItemDetail =& xoonips_getormhandler('xnpbook', 'item_detail'); $oItemDetail =& $hItemDetail->get($book_id); $oItemDetail->setVars($ar, true); // not gpc if (!$hItemDetail->insert($oItemDetail)) { error_log('xnpbook: cannot update item_detail - ' . implode(', ', $oItemDetail->getErrors())); return false; } // insert/update author $formdata =& xoonips_getutility('formdata'); $author_handler =& xoonips_getormhandler('xnpbook', 'author'); $author_objs =& $formdata->getObjectArray('post', $author_handler->getTableName(), $author_handler, false); if (!$author_handler->updateAllObjectsByForeignKey('book_id', $book_id, $author_objs)) { return false; } return true; }
function xnpmodelUpdateItem($item_id) { global $xoopsDB; $formdata =& xoonips_getutility('formdata'); $xnpsid = $_SESSION['XNPSID']; // edit BasicInformation, Index, Preview, Attachment $result = xnpUpdateBasicInformation($item_id); if ($result) { $result = xnpUpdateIndex($item_id); if ($result) { $result = xnpUpdatePreview($item_id); if ($result) { $result = xnpUpdateAttachment($item_id, 'model_data'); if ($result) { $result = xnp_insert_change_log($xnpsid, $item_id, $formdata->getValue('post', 'change_log', 's', false)); $result = !$result; if (!$result) { echo ' xnp_insert_change_log failed.'; } } else { echo ' xnpUpdateAttachment failed.'; } } else { echo ' xnpUpdatePreview failed.'; } } else { echo ' xnpUpdateIndex failed.'; } } else { echo ' xnpUpdateBasicInformation failed.'; } if (!$result) { return false; } list($rights, $use_cc, $cc_commercial_use, $cc_modification) = xnpGetRights(); // it makes strings with constant length $ar = array('model_type' => $formdata->getValue('post', 'model_type', 's', false), 'readme' => xnpGetTextFile('readme'), 'rights' => $rights); xnpTrimColumn($ar, 'xnpmodel_item_detail', array_keys($ar), _CHARSET); // insert Detail Information $attachment_dl_limit = $formdata->getValue('post', 'attachment_dl_limit', 'i', false); $attachment_dl_notify = $formdata->getValue('post', 'attachment_dl_notify', 'i', false); $keyval = array('attachment_dl_limit' . '=\'' . $attachment_dl_limit . '\'', 'attachment_dl_notify' . '=\'' . ($attachment_dl_limit ? $attachment_dl_notify : 0) . '\'', 'model_type' . '=\'' . addslashes($ar['model_type']) . '\'', 'readme' . '=\'' . addslashes($ar['readme']) . '\'', 'rights' . '=\'' . addslashes($ar['rights']) . '\'', 'use_cc' . '=\'' . $use_cc . '\'', 'cc_commercial_use' . '=\'' . $cc_commercial_use . '\'', 'cc_modification' . '=\'' . $cc_modification . '\''); // edit DetailInformation $sql = 'update ' . $xoopsDB->prefix('xnpmodel_item_detail') . ' set ' . implode(', ', $keyval) . " where model_id={$item_id}"; $result = $xoopsDB->queryF($sql); if ($result == false) { echo 'cannot update item_detail'; echo "\n{$sql}"; return false; } // insert/update creator $creator_handler =& xoonips_getormhandler('xnpmodel', 'creator'); $creator_objs =& $formdata->getObjectArray('post', $creator_handler->getTableName(), $creator_handler, false); if (!$creator_handler->updateAllObjectsByForeignKey('model_id', $item_id, $creator_objs)) { return false; } return true; }
function xnpconferenceUpdateItem($item_id) { global $xoopsDB; $formdata =& xoonips_getutility('formdata'); $xnpsid = $_SESSION['XNPSID']; // edit BasicInformation, Index, Preview, Attachment $_POST['publicationDateYear'] = addslashes($formdata->getValue('post', 'conferenceFromYear', 'i', false)); $_POST['publicationDateMonth'] = addslashes($formdata->getValue('post', 'conferenceFromMonth', 'i', false)); $_POST['publicationDateDay'] = addslashes($formdata->getValue('post', 'conferenceFromDay', 'i', false)); $result = xnpUpdateBasicInformation($item_id); if ($result) { $result = xnpUpdateIndex($item_id); if ($result) { $result = xnpUpdatePreview($item_id); if ($result) { $result = xnpUpdateAttachment($item_id, 'conference_file'); if ($result) { $result = xnpUpdateAttachment($item_id, 'conference_paper'); if ($result) { $result = xnp_insert_change_log($xnpsid, $item_id, $formdata->getValue('post', 'change_log', 's', false)); $result = !$result; if (!$result) { echo ' xnp_insert_change_log failed.'; } } } else { echo ' xnpUpdateAttachment failed.'; } } else { echo ' xnpUpdatePreview failed.'; } } else { echo ' xnpUpdateIndex failed.'; } } else { echo ' xnpUpdateBasicInformation failed.'; } if (!$result) { return false; } // register DetailInformation // trim strings $ar = array('presentation_type' => $formdata->getValue('post', 'presentation_type', 's', false), 'conference_title' => $formdata->getValue('post', 'conference_title', 's', false), 'place' => $formdata->getValue('post', 'place', 's', false), 'abstract' => $formdata->getValue('post', 'abstract', 's', false)); xnpTrimColumn($ar, 'xnpconference_item_detail', array_keys($ar), _CHARSET); $attachment_dl_limit = $formdata->getValue('post', 'attachment_dl_limit', 'i', false); $attachment_dl_notify = $formdata->getValue('post', 'attachment_dl_notify', 'i', false); $sql = implode(',', array('attachment_dl_limit' . '=\'' . $attachment_dl_limit . '\'', 'attachment_dl_notify' . '=\'' . ($attachment_dl_limit ? $attachment_dl_notify : 0) . '\'', 'presentation_type' . '=\'' . addslashes($ar['presentation_type']) . '\'', 'conference_title' . '=\'' . addslashes($ar['conference_title']) . '\'', 'place' . '=\'' . addslashes($ar['place']) . '\'', 'abstract' . '=\'' . addslashes($ar['abstract']) . '\'', 'conference_from_year' . '=\'' . addslashes($formdata->getValue('post', 'conferenceFromYear', 'i', false)) . '\'', 'conference_from_month' . '=\'' . addslashes($formdata->getValue('post', 'conferenceFromMonth', 'i', false)) . '\'', 'conference_from_mday' . '=\'' . addslashes($formdata->getValue('post', 'conferenceFromDay', 'i', false)) . '\'', 'conference_to_year' . '=\'' . addslashes($formdata->getValue('post', 'conferenceToYear', 'i', false)) . '\'', 'conference_to_month' . '=\'' . addslashes($formdata->getValue('post', 'conferenceToMonth', 'i', false)) . '\'', 'conference_to_mday' . '=\'' . addslashes($formdata->getValue('post', 'conferenceToDay', 'i', false)) . '\'')); $result = $xoopsDB->queryF('update ' . $xoopsDB->prefix('xnpconference_item_detail') . " set {$sql} where conference_id = {$item_id} "); if ($result == false) { return false; } // insert/update author $author_handler =& xoonips_getormhandler('xnpconference', 'author'); $author_objs =& $formdata->getObjectArray('post', $author_handler->getTableName(), $author_handler, false); if (!$author_handler->updateAllObjectsByForeignKey('conference_id', $item_id, $author_objs)) { return false; } return true; }
function xnppaperUpdateItem($item_id) { global $xoopsDB; $formdata =& xoonips_getutility('formdata'); $xnpsid = $_SESSION['XNPSID']; // modify BasicInformation, Index, Attachment $result = xnpUpdateBasicInformation($item_id); if ($result) { $result = xnpUpdateIndex($item_id); if ($result) { $result = xnpUpdateAttachment($item_id, 'paper_pdf_reprint'); if ($result) { $result = xnp_insert_change_log($xnpsid, $item_id, $formdata->getValue('post', 'change_log', 's', false)); $result = !$result; if (!$result) { error_log('xnp_insert_change_log failed.'); } } else { error_log('xnpUpdateAttachment failed.'); } } else { error_log('xnpUpdateIndex failed.'); } } else { error_log('xnpUpdateBasicInformation failed.'); } if (!$result) { return false; } // trim strings $journal = $formdata->getValue('post', 'journal', 's', false); $volume = $formdata->getValue('post', 'volume', 's', false); $number = $formdata->getValue('post', 'number', 's', false); $page = $formdata->getValue('post', 'page', 's', false); $abstract = $formdata->getValue('post', 'abstract', 's', false); $pubmed_id = $formdata->getValue('post', 'pubmed_id', 's', false); $ar = array('journal' => $journal, 'page' => $page, 'abstract' => $abstract, 'pubmed_id' => $pubmed_id); xnpTrimColumn($ar, 'xnppaper_item_detail', array_keys($ar), _CHARSET); // register detail information $sql = implode(',', array('journal' . '=\'' . addslashes($ar['journal']) . '\'', 'volume' . '=' . (strlen($volume) == 0 ? 'null' : (int) $volume), 'number' . '=' . (strlen($number) == 0 ? 'null' : (int) $number), 'page' . '=' . (strlen($page) == 0 ? 'null' : '\'' . addslashes($ar['page']) . '\''), 'abstract' . '=' . (strlen($abstract) == 0 ? 'null' : '\'' . addslashes($ar['abstract']) . '\''), 'pubmed_id' . '=' . (strlen($pubmed_id) == 0 ? 'null' : '\'' . addslashes($ar['pubmed_id']) . '\''))); $result = $xoopsDB->queryF('update ' . $xoopsDB->prefix('xnppaper_item_detail') . " set {$sql} where paper_id = {$item_id} "); if ($result == false) { return false; } // insert/update author $author_handler =& xoonips_getormhandler('xnppaper', 'author'); $author_objs =& $formdata->getObjectArray('post', $author_handler->getTableName(), $author_handler, false); if (!$author_handler->updateAllObjectsByForeignKey('paper_id', $item_id, $author_objs)) { return false; } return true; }
function xnpmemoUpdateItem($item_id) { global $xoopsDB; $formdata =& xoonips_getutility('formdata'); $xnpsid = $_SESSION['XNPSID']; // edit BasicInformation, Index, Preview, Attachment $result = xnpUpdateBasicInformation($item_id); if ($result) { $result = xnpUpdateIndex($item_id); if ($result) { $result = xnpUpdateAttachment($item_id, 'memo_file'); if ($result) { $result = xnp_insert_change_log($xnpsid, $item_id, $formdata->getValue('post', 'change_log', 's', false)); $result = !$result; if (!$result) { echo ' xnp_insert_change_log failed.'; } } else { echo ' xnpUpdateAttachment failed.'; } } else { echo ' xnpUpdateIndex failed.'; } } else { echo ' xnpUpdateBasicInformation failed.'; } if (!$result) { return false; } $ar = array('item_link' => preg_replace('/javascript:/i', '', preg_replace('/[\\x00-\\x20\\x22\\x27]/', '', $formdata->getValue('post', 'item_link', 's', false)))); xnpTrimColumn($ar, 'xnpmemo_item_detail', array_keys($ar), _CHARSET); // register DetailInformation $sql = implode(',', array('item_link' . '=\'' . addslashes($ar['item_link']) . '\'')); $result = $xoopsDB->queryF('update ' . $xoopsDB->prefix('xnpmemo_item_detail') . " set {$sql} where memo_id = {$item_id} "); if ($result == false) { return false; } return true; }
/** generate PreviewBlock HTML in edit page * @param item_id false(no HTML) */ function xnpGetPreviewEditBlock($item_id) { global $xoopsDB; $textutil =& xoonips_getutility('text'); $errorHTML = $errorMessage = $errorMessage1 = $errorMessage2 = ''; $files = array(); $formdata =& xoonips_getutility('formdata'); $previewFileID = $formdata->getValue('post', 'previewFileID', 's', false); if (isset($previewFileID)) { // User comes from some edit pages. if ($previewFileID == "") { $previewFileIDs = array(); } else { // illegal inputs are removed. if (!xnpIsCommaSeparatedNumber($previewFileID)) { echo "Error: bad previewFileID"; return false; } $previewFileIDs = explode(',', $previewFileID); } // process of upload/delete $mode = $formdata->getValue('post', 'mode', 's', false); if (empty($mode)) { } else { if ($mode == 'Upload') { // upload something $preview = $formdata->getFile('preview', false); if (!empty($preview['name'])) { $keyval = array(); $keyval['caption'] = $formdata->getValue('post', 'previewCaption', 's', false); xnpTrimColumn($keyval, 'xoonips_file', array_keys($keyval), _CHARSET); if (!is_uploaded_file($preview['tmp_name'])) { $errorMessage = "Unexpected file(not uploaded file?). '" . $preview['name'] . "'"; } else { $preview = $formdata->getFile('preview', false); $fileutil =& xoonips_getutility('file'); $keyval['thumbnail_file'] = $fileutil->get_thumbnail($preview['tmp_name'], $preview['type']); if (empty($keyval['thumbnail_file'])) { // unknown image formats $errorMessage = _MD_XOONIPS_ITEM_THUMBNAIL_BAD_FILETYPE; } else { list($fileID, $errorMessage2) = xnpUploadFile('preview', $keyval); if ($fileID) { $previewFileIDs[] = $fileID; } if ($errorMessage2) { $errorMessage = $errorMessage2; } } } $_SESSION['xoonips_preview_message'] = $errorMessage; } else { if (isset($_SESSION['xoonips_preview_message'])) { $errorMessage = $_SESSION['xoonips_preview_message']; } } } else { if ($mode == 'Delete') { // $_POST['file_id'] delete from $previewFileID. $ar = array(); $fileID = $formdata->getValue('post', 'fileID', 'i', false); foreach ($previewFileIDs as $value) { if ($value != $fileID) { $ar[] = $value; } } $previewFileIDs = $ar; } } } // previewFileID -> files if (count($previewFileIDs)) { $sql = "t_file.file_id in (" . implode(',', $previewFileIDs) . ")"; $files = xnpGetFileInfo("t_file.file_id, t_file.caption", "t_file_type.name='preview' and {$sql} ", $item_id); } // Value of previewFileID are returned to $_POST ( Value of $_POST is saved and restored on register.php ). $formdata->set('post', 'previewFileID', implode(',', $previewFileIDs)); } else { // get default value from database. if (!empty($item_id)) { $files = xnpGetFileInfo("t_file.file_id, t_file.caption", "t_file_type.name='preview' and is_deleted=0 and item_id={$item_id} ", $item_id); } } // display files in HTML format. $ar = array(); reset($files); while (list($key, list($fileID, $caption)) = each($files)) { $ar[] = $fileID; } $previewFileID = implode(',', $ar); if ($errorMessage) { $errorHTML = '<span style="color: red;">' . $textutil->html_special_chars($errorMessage) . '</span><br />'; } $uploadHtml = '<input type="hidden" name="previewFileID" value="' . $previewFileID . '"/>' . $errorHTML; $uploadHtml .= '<table>'; $uploadHtml .= '<tr>'; $uploadHtml .= '<td style="width: 100px;">' . _MD_XOONIPS_ITEM_FILE_HEAD_LABEL . '</td>'; $uploadHtml .= '<td><input size="30" type="file" name="preview"/>'; $uploadHtml .= '<input class="formButton" type="button" name="preview_upload_button_' . $fileID . '" value="' . _MD_XOONIPS_ITEM_UPLOAD_LABEL . '" onclick="xnpSubmitFileUpload(this.form, \'preview\')"/></td>'; $uploadHtml .= '</tr>'; $uploadHtml .= '<tr>'; $uploadHtml .= '<td style="width: 100px;">' . _MD_XOONIPS_ITEM_CAPTION_HEAD_LABEL . '</td>'; $uploadHtml .= '<td><input size="30" type="text" name="previewCaption"/></td>'; $uploadHtml .= '</tr>'; $uploadHtml .= '</table>' . "\n"; $imageHtml1 = array(); $imageHtml2 = array(); $imageHtml3 = array(); reset($files); while (list($dummy, list($fileID, $caption)) = each($files)) { $thumbnailFileName = XOOPS_URL . "/modules/xoonips/image.php?file_id={$fileID}&thumbnail=1"; $imageFileName = XOOPS_URL . "/modules/xoonips/image.php?file_id={$fileID}"; $htmlCaption = $textutil->html_special_chars($caption); $imageHtml1[] = '<a href="' . $imageFileName . '" target="_blank"><img src="' . $thumbnailFileName . '" alt="thumbnail"/></a>'; $imageHtml2[] = "{$htmlCaption}"; $imageHtml3[] = '<input class="formButton" type="button" name="preview_delete_button_' . $fileID . '" value="' . _MD_XOONIPS_ITEM_DELETE_BUTTON_LABEL . '" onclick="xnpSubmitFileDelete( this.form, \'preview\', ' . $fileID . ' )"/>'; } $html = xnpMakeTable(array($imageHtml1, $imageHtml2, $imageHtml3), 3); return array('name' => _MD_XOONIPS_ITEM_PREVIEW_LABEL, 'value' => $uploadHtml . $html); }