function save_presentation()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     ajx_current("empty");
     $postFile = array_var($_POST, 'file');
     $fileid = array_var($postFile, 'id');
     if ($fileid > 0) {
         //edit presentation
         try {
             $file = ProjectFiles::findById($fileid);
             if (!$file->canEdit(logged_user())) {
                 flash_error(lang('no access permissions'));
                 ajx_current("empty");
                 return;
             }
             // if
             DB::beginWork();
             $post_revision = array_var($_POST, 'new_revision_document') == 'checked';
             // change file?
             $revision_comment = '';
             $file_dt['name'] = $file->getFilename();
             $file_content = unescapeSLIM(array_var($_POST, 'slimContent'));
             $file_dt['size'] = strlen($file_content);
             $file_dt['type'] = 'prsn';
             $file_dt['tmp_name'] = ROOT . '/tmp/' . rand();
             $handler = fopen($file_dt['tmp_name'], 'w');
             fputs($handler, $file_content);
             fclose($handler);
             $file->setFilename(array_var($postFile, 'name'));
             $file->save();
             $file->handleUploadedFile($file_dt, $post_revision, $revision_comment);
             if (array_var($_POST, 'checkin', false)) {
                 $file->checkIn();
                 ajx_current("back");
             }
             $ws = $file->getWorkspaces();
             ApplicationLogs::createLog($file, $ws, ApplicationLogs::ACTION_EDIT);
             DB::commit();
             unlink($file_dt['tmp_name']);
             flash_success(lang('success save file', $file->getFilename()));
             evt_add("presentation saved", array("id" => $file->getId()));
             //$this->redirectTo('files', 'add_presentation', array('id' => $file->getId()));
             ajx_add("overview-panel", "reload");
         } catch (Exception $e) {
             DB::rollback();
             unlink($file_dt['tmp_name']);
             flash_error(lang('error while saving'));
             //$this->redirectToUrl(get_url('files'));
         }
         // try
     } else {
         // new presentation
         if (!ProjectFile::canAdd(logged_user(), active_or_personal_project())) {
             flash_error(lang('no access permissions'));
             $this->redirectToReferer(get_url('files'));
             return;
         }
         // if
         // prepare the file object
         $file = new ProjectFile();
         $file->setFilename(array_var($postFile, 'name'));
         $file->setIsVisible(true);
         $file->setIsPrivate(false);
         $file->setIsImportant(false);
         $file->setCommentsEnabled(true);
         $file->setAnonymousCommentsEnabled(false);
         //seteo esto para despues setear atributos
         $file_content = unescapeSLIM(array_var($_POST, 'slimContent'));
         $file_dt['name'] = array_var($postFile, 'name');
         $file_dt['size'] = strlen($file_content);
         $file_dt['type'] = 'prsn';
         $file->setCreatedOn(new DateTimeValue(time()));
         try {
             DB::beginWork();
             $file_dt['tmp_name'] = ROOT . '/tmp/' . rand();
             $handler = fopen($file_dt['tmp_name'], 'w');
             fputs($handler, unescapeSLIM(array_var($_POST, 'slimContent')));
             fclose($handler);
             $file->save();
             $file->subscribeUser(logged_user());
             $file->addToWorkspace(active_or_personal_project());
             $revision = $file->handleUploadedFile($file_dt, true);
             if (config_option('checkout_for_editing_online')) {
                 $file->checkOut(true, logged_user());
             }
             $ws = $file->getWorkspaces();
             ApplicationLogs::createLog($file, $ws, ApplicationLogs::ACTION_ADD);
             DB::commit();
             flash_success(lang('success save file', $file->getFilename()));
             evt_add("presentation saved", array("id" => $file->getId()));
             unlink($file_dt['tmp_name']);
             //$this->redirectTo('files', 'add_presentation', array('id' => $file->getId()));
         } catch (Exception $e) {
             DB::rollback();
             //tpl_assign('error', $e);
             tpl_assign('file', new ProjectFile());
             // reset file
             unlink($file_dt['tmp_name']);
             // if we uploaded the file remove it from repository
             if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) {
                 FileRepository::deleteFile($revision->getRepositoryId());
             }
             // if
             flash_error(lang('error while saving'));
             //$this->redirectToUrl(get_url('files'));
         }
         // try
     }
 }
	function save_presentation() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		ajx_current("empty");
		$postFile = array_var($_POST, 'file');
		$fileid = array_var($postFile, 'id');
		if($fileid > 0) {
			//edit presentation
			try {
				$file = ProjectFiles::findById($fileid);
				if (!$file->canEdit(logged_user())) {
					flash_error(lang('no access permissions'));
					ajx_current("empty");
					return;
				} // if
				DB::beginWork();
				$post_revision = array_var($_POST, 'new_revision_document') == 'checked'; // change file?
				$revision_comment = '';

				$file_dt['name'] = $file->getFilename();
				$file_content = unescapeSLIM(array_var($_POST, 'slimContent'));
				$file_dt['size'] = strlen($file_content);
				$file_dt['type'] = 'prsn';
				$file_dt['tmp_name'] = ROOT . '/tmp/' . rand() ;
				$handler = fopen($file_dt['tmp_name'], 'w');
				fputs($handler,$file_content);
				fclose($handler);
				$file->setFilename(array_var($postFile, 'name'));
				$file->save();
				$file->handleUploadedFile($file_dt, $post_revision, $revision_comment);
				
				if (array_var($_POST, 'checkin', false)) {
					$file->checkIn();
					ajx_current("back");
				}
				
				ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT);

				DB::commit();
				unlink($file_dt['tmp_name']);

				flash_success(lang('success save file', $file->getFilename()));
				evt_add("presentation saved", array("id" => $file->getId()));
				
				ajx_add("overview-panel", "reload");
			} catch(Exception $e) {
				DB::rollback();
				unlink($file_dt['tmp_name']);
				flash_error(lang('error while saving'));
				
			} // try
		} else  {
			// new presentation
			$notAllowedMember = '';
			if (!ProjectFile::canAdd(logged_user(), active_context(), $notAllowedMember)) {
				if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
				else flash_error(lang('no context permissions to add',lang("presentations"),$notAllowedMember));
				$this->redirectToReferer(get_url('files'));
				return ;
			} // if

			// prepare the file object
			$file = new ProjectFile();
			$file->setFilename(array_var($postFile, 'name'));
			$file->setIsVisible(true);

			//seteo esto para despues setear atributos
			$file_content = unescapeSLIM(array_var($_POST, 'slimContent'));
			$file_dt['name'] = array_var($postFile, 'name');
			$file_dt['size'] = strlen($file_content);
			$file_dt['type'] = 'prsn';

			$file->setCreatedOn(new DateTimeValue(time()) );
			try {
				DB::beginWork();
				$file_dt['tmp_name'] = ROOT . '/tmp/' . rand ();
				$handler = fopen($file_dt['tmp_name'], 'w');
				fputs($handler, unescapeSLIM(array_var($_POST, 'slimContent')));
				fclose($handler);

				$file->save();
				$file->subscribeUser(logged_user());
				$revision = $file->handleUploadedFile($file_dt, true);

				if (config_option('checkout_for_editing_online')) {
					$file->checkOut(true, logged_user());
				}
				
				ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD);

				$object_controller = new ObjectController();
				
				// file is added to current context members
				$member_ids = array();
				$selection = active_context();
				foreach ($selection as $member) {
					if ($member instanceof Member) $member_ids[] = $member->getId();
				}
				$object_controller->add_to_members($file, $member_ids);
				
				DB::commit();
				flash_success(lang('success save file', $file->getFilename()));
				evt_add("presentation saved", array("id" => $file->getId()));
				unlink($file_dt['tmp_name']);
				
			} catch(Exception $e) {
				DB::rollback();
				
				tpl_assign('file', new ProjectFile()); // reset file
				unlink($file_dt['tmp_name']);
				// if we uploaded the file remove it from repository
				if	(isset($revision) && ($revision instanceof ProjectFileRevision) && FileRepository::isInRepository($revision->getRepositoryId())) {
					FileRepository::deleteFile($revision->getRepositoryId());
				}
				flash_error(lang('error while saving').": ".$e->getMessage());
				
			} // try
		}
	}
Example #3
0
function unescapeSLIM($encodedSLIM)
{
    return rawurldecode($encodedSLIM);
}
?>

<h1>This is what the server gets:</h1>

Filename: <input type="text" value="<?php 
echo $_POST['filename'];
?>
" />

<br /><br />

Slim Content:<br />
<textarea rows="2" cols="80"><?php 
echo $_POST['slimContent'];
?>
</textarea>

<br /><br />

Unescaped Slim Content:<br />
<textarea rows="5" cols="80"><?php 
echo unescapeSLIM(unescapeSLIM($_POST['slimContent']));
?>
</textarea>

</body>
</html>