function itemsSetPubLevel() { global $PH; $ids = getPassedIds('item', 'items_*'); global $g_pub_level_names; if (!$ids) { $PH->abortWarning(__("Select some items(s) to change pub level"), ERROR_NOTE); return; } if (!($new_pub_level = get('item_pub_level')) || !isset($g_pub_level_names[$new_pub_level])) { $PH->abortWarning("itemsSetPubLevel requires item_pub_level", ERROR_NOTE); return; } $count = 0; $num_errors = 0; foreach ($ids as $id) { if ($item = DbProjectItem::getEditableById($id)) { $count++; $item->pub_level = $new_pub_level; $item->update(); } else { $num_errors++; } } new FeedbackMessage(sprintf(__("Made %s items public to %s"), $count, $g_pub_level_names[$new_pub_level])); if ($num_errors) { new FeedbackWarning(sprintf(__("%s error(s) occured"), $num_errors)); } ### return to from-page ### if (!$PH->showFromPage()) { $PH->show('home'); } }
/** * Restoring (i.e. undelete) items @ingroup pages */ function itemsRestore() { global $PH; ### get effort #### $ids = getPassedIds('item', 'items_*'); if (!$ids) { $PH->abortWarning(__("Select some items to restore")); return; } $counter = 0; $errors = 0; foreach ($ids as $id) { $i = DbProjectItem::getEditableById($id); if (!$i) { $PH->abortWarning("Invalid item-id!"); } if ($i->state != -1) { new FeedbackMessage(sprintf(__('Item %s does not need to be restored'), $i->id)); $errors++; continue; } $i->state = 1; if ($i->update()) { $counter++; } else { $errors++; } } if ($errors) { new FeedbackWarning(sprintf(__("Failed to restore %s items"), $errors)); } else { new FeedbackMessage(sprintf(__("Restored %s items"), $counter)); } if (!$PH->showFromPage()) { $PH->show('home'); } }
/** * save field value of an item which has been edited inplace * and return formatted html code. * * If only a chapter has been edited, number defined in "chapter" */ function itemSaveField() { header("Content-type: text/html; charset=utf-8"); ### disable page caching ### header("Expires: -1"); header("Cache-Control: post-check=0, pre-check=0"); header("Pragma: no-cache"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); $value = get('value'); if (is_null($value)) { return; } if (!($item_id = get('item'))) { print "Failure"; return; } global $g_wiki_project; if (!($item = DbProjectItem::getEditableById($item_id))) { print "Failure"; return; } if (!($object = DbProjectItem::getObjectById($item_id))) { print "Failure"; return; } if ($item->type == ITEM_PROJECT) { if (!($project = Project::getVisibleById($item->id))) { print "Failure getting project"; return; } } else { if (!($project = Project::getVisibleById($item->project))) { print "Failure getting project"; return; } } $g_wiki_project = $project; $field_name = 'description'; if (get('field')) { $field_name = asCleanString(get('field')); } if (!isset($object->fields[$field_name])) { return NULL; } require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; $chapter = intVal(get('chapter')); ### replace complete field ### if (is_null($chapter)) { $object->{$field_name} = $value; } else { require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; /** * split originial wiki block into chapters * start with headline and belonging text */ $org = $object->{$field_name}; if ($object->type == ITEM_TASK) { global $g_wiki_task; $g_wiki_task = $object; } $parts = getWikiChapters($org); ### replace last line return (added by textarea) ### if (!preg_match("/\n\$/", $value)) { $value .= "\n"; } #$value= str_replace("\\'", "'", $value); #$value= str_replace('\\"', "\"", $value); $parts[$chapter] = $value; $new_wiki_text = implode('', $parts); $object->{$field_name} = $new_wiki_text; } ### update $object->update(array($field_name)); ### mark parent of comment as changes if ($item->type == ITEM_COMMENT) { if ($parent_task = Task::getById($object->task)) { print "calling now changed by user"; $parent_task->nowChangedByUser(); } } print wiki2purehtml($object->{$field_name}); $item->nowChangedByUser(); }
/** * Submit information to a file @ingroup pages * * read more at http://www.streber-pm.org/3658 */ function fileEditSubmit() { global $PH; ### Validate form crc if (!validateFormCrc()) { $PH->abortWarning(__('Invalid checksum for hidden form elements')); } $id = getOnePassedId('file'); ### temp new file-object #### if ($id == 0) { $file = new File(array('id' => 0)); $file->mimetype = get('file_mimetype') ? urldecode(get('file_mimetype')) : NULL; $file->org_filename = get('file_org_filename') ? urldecode(get('file_org_filename')) : NULL; $file->tmp_filename = get('file_tmp_filename') ? urldecode(get('file_tmp_filename')) : NULL; $file->tmp_dir = get('file_tmp_dir') ? get('file_tmp_dir') : NULL; ### make sure file is not already uploaded ### #if(!file_exists("_uploads/". $file->tmp_dir)) { # $PH->abortWarning("Not again"); #} $file->filesize = intval(get('file_filesize')); $file->is_image = intval(get('file_is_image')); $file->version = intval(get('file_version')); $file->parent_item = intval(get('file_parent_item')); $file->org_file = intval(get('file_org_file')); } else { $file = File::getEditableById($id); if (!$file) { $PH->abortWarning(__("Could not get file")); return; } } ### cancel ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $file->project)); } exit; } $file->project = get('file_project'); if (!($project = Project::getVisibleById($file->project))) { $PH->abortWarning(__("Could not get project of file")); } if (!is_null(get('file_name'))) { $file->name = get('file_name'); } if (!is_null(get('file_description'))) { $file->description = get('file_description'); } if (!is_null(get('file_status'))) { $file->status = get('file_status'); } ### pub level ### if ($pub_level = get('file_pub_level')) { ### not a new file ### if ($file->id) { if ($pub_level > $file->getValidUserSetPublicLevels()) { $PH->abortWarning('invalid data', ERROR_RIGHTS); } } else { #@@@ check for person create rights $foo = true; } $file->pub_level = $pub_level; } ### go back to from if validation fails ### $failure = false; if ($file->name == "") { $failure = true; $PH->messages[] = __("Please enter a proper filename"); } if ($failure) { $PH->show('fileEdit', NULL, $file); exit; } ### write to db ### if ($file->id == 0) { $latest_file = NULL; if ($file->org_file) { if (!($org_file = File::getEditableById($file->org_file))) { $PH->abortWarning("unable to write parent file", ERROR_RIGHTS); } if (!($latest_file = $org_file->getLatest())) { $PH->abortWarning("unable to get latest file", ERROR_RIGHTS); } } if (!$file->insert()) { $PH->abortWarning("Could not insert file to db"); } ### updated former latest file? ### if ($latest_file) { $latest_file->is_latest = 0; $latest_file->update(); new FeedbackMessage(sprintf(__("Uploaded new version of file with Id %s"), $file->id)); } else { new FeedbackMessage(sprintf(__("Uploaded new file with Id %s"), $file->id)); } } else { new FeedbackMessage(sprintf(__("Updated file with Id %s"), $file->id)); $file->update(); } ### update date of parent items ? ### if ($item = DbProjectItem::getEditableById($file->parent_item)) { $item->update(array()); } ### display taskView #### if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $file->project)); } }