示例#1
0
 function testRevisionSave()
 {
     $ret = $GLOBALS['db']->query("SELECT COUNT(*) AS rowcount1 FROM document_revisions WHERE document_id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['rowcount1'], 0, 'We created an empty revision');
     $ret = $GLOBALS['db']->query("SELECT document_revision_id FROM documents WHERE id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertTrue(empty($row['document_revision_id']), 'We linked the document to a fake document_revision');
     $ds = new DocumentSoap();
     $revision_stuff = array('file' => base64_encode('Pickles has an extravagant beard of pine fur.'), 'filename' => 'a_file_about_pickles.txt', 'id' => $this->doc->id, 'revision' => '1');
     $revisionId = $ds->saveFile($revision_stuff);
     $ret = $GLOBALS['db']->query("SELECT COUNT(*) AS rowcount1 FROM document_revisions WHERE document_id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['rowcount1'], 1, 'We didn\'t create a revision when we should have');
     $ret = $GLOBALS['db']->query("SELECT document_revision_id FROM documents WHERE id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['document_revision_id'], $revisionId, 'We didn\'t link the newly created document revision to the document');
     // Double saving doesn't work because save doesn't reset the new_with_id
     $newDoc = new Document();
     $newDoc->retrieve($this->doc->id);
     $newDoc->document_revision_id = $revisionId;
     $newDoc->save(FALSE);
     $ret = $GLOBALS['db']->query("SELECT COUNT(*) AS rowcount1 FROM document_revisions WHERE document_id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['rowcount1'], 1, 'We didn\'t create a revision when we should have');
     $ret = $GLOBALS['db']->query("SELECT document_revision_id FROM documents WHERE id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['document_revision_id'], $revisionId, 'We didn\'t link the newly created document revision to the document');
 }
 function saveFile($document, $portal = false)
 {
     global $sugar_config;
     $focus = new Document();
     if (!empty($document['id'])) {
         $focus->retrieve($document['id']);
     } else {
         return '-1';
     }
     if (!empty($document['file'])) {
         $decodedFile = base64_decode($document['file']);
         $this->upload_file->set_for_soap($document['filename'], $decodedFile);
         $ext_pos = strrpos($this->upload_file->stored_file_name, ".");
         $this->upload_file->file_ext = substr($this->upload_file->stored_file_name, $ext_pos + 1);
         if (in_array($this->upload_file->file_ext, $sugar_config['upload_badext'])) {
             $this->upload_file->stored_file_name .= ".txt";
             $this->upload_file->file_ext = "txt";
         }
         $revision = new DocumentRevision();
         $revision->filename = $this->upload_file->get_stored_file_name();
         $revision->file_mime_type = $this->upload_file->getMimeSoap($revision->filename);
         $revision->file_ext = $this->upload_file->file_ext;
         //$revision->document_name = ;
         $revision->revision = $document['revision'];
         $revision->document_id = $document['id'];
         $revision->save();
         $focus->document_revision_id = $revision->id;
         $focus->save();
         $return_id = $revision->id;
         $this->upload_file->final_move($revision->id);
     } else {
         return '-1';
     }
     return $return_id;
 }
示例#3
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $document = new Document($id);
         $_POST['user_id'] = $this->session->userdata('id');
         $_POST['start_date'] = Date2DB($_POST['start_date']);
         $document->from_array($_POST);
         $document->save();
         fix_file($_FILES['file']);
         foreach ($_POST['doc'] as $key => $doc) {
             if (@$_FILES['file'][$key]['name'] || @$_POST['doc_id'][$key]) {
                 $document_file = new Document_file(@$_POST['doc_id'][$key]);
                 if ($_FILES['file'][$key]['name']) {
                     if (@$_POST['doc_id'][$key]) {
                         $document_file->delete_file('uploads/document', 'file');
                     }
                     $document_file->file = $document_file->upload($_FILES['file'][$key], 'uploads/document');
                 }
                 $document_file->name = $doc;
                 $document_file->document_id = $document->id;
                 $document_file->save();
             }
         }
         set_notify('success', lang('save_data_complete'));
     }
     redirect('documents');
 }
 public function run($type, $id, $contentKey = null, $user)
 {
     if (isset($_FILES['avatar'])) {
         $type = trim($type);
         $folder = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR);
         $pathImage = $this->processImage($_FILES['avatar'], $id, $type);
         if ($pathImage) {
             $params = array();
             $params["id"] = $id;
             $params["type"] = $type;
             $params['folder'] = $folder;
             $params['moduleId'] = Yii::app()->controller->module->id;
             $params['name'] = $pathImage["name"];
             $params['doctype'] = "image";
             $params['size'] = $pathImage["size"][0] * $pathImage["size"][1] / 1000;
             $params['author'] = $user;
             $params['category'] = array();
             $params['contentKey'] = $contentKey;
             $result = Document::save($params);
             //Profile to check
             $urlBdd = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . "upload" . DIRECTORY_SEPARATOR . Yii::app()->controller->module->id . $folder . $pathImage["name"]);
             Document::setImagePath($id, $type, $urlBdd, $contentKey);
             $newImage = Document::getById($result["id"]);
         }
         $res = array('result' => true, 'msg' => 'The picture was uploaded', 'imagePath' => $urlBdd, "id" => $result["id"], "image" => $newImage);
         Rest::json($res);
         Yii::app()->end();
     }
 }
示例#5
0
 /**
  * Save Document
  * @param  [type] $data    [description]
  * @param  array  $options [description]
  * @return [type] [description]
  */
 public function save(array &$data, array $options = array())
 {
     $document = new Document($data, $this);
     $save = $document->save($options);
     $data = $document->data;
     return $save;
 }
示例#6
0
文件: list.php 项目: AliEksi/DokuDok
 public function addNews()
 {
     foreach ($this->fileArray as $file) {
         $title = explode(".", $file)[0];
         $book = new Document($this->path, $file, $title);
         $book->save();
     }
 }
示例#7
0
 public function setUp()
 {
     global $current_user, $currentModule;
     $mod_strings = return_module_language($GLOBALS['current_language'], "Documents");
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     $document = new Document();
     $document->id = uniqid();
     $document->name = 'Test Document';
     $document->save();
     $this->doc = $document;
 }
 function create()
 {
     $document = new Document();
     $document->organization_id = $_SESSION['organization_id'];
     $document->name = $_POST['name'];
     $document->year = $_POST['year'];
     if ($document->save()) {
         $this->redirect('/documents/' . $document->id);
     } else {
         $this->redirect('/documents');
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Document();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Document'])) {
         $model->attributes = $_POST['Document'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->ID));
         }
     }
     $this->render('create', array('model' => $model));
 }
 function create()
 {
     $document = new Document();
     $document->organization_id = $_SESSION['organization_id'];
     $document->name = $_POST['name'];
     $document->year = $_POST['year'];
     $document->logo = '381554527568a0188078c34.22685210ibip.jpg';
     if ($document->save()) {
         $document->generate($this->sections);
         $this->redirect('/documents/' . $document->id);
     } else {
         $this->redirect('/documents');
     }
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aJournalEntry !== null) {
             if ($this->aJournalEntry->isModified() || $this->aJournalEntry->isNew()) {
                 $affectedRows += $this->aJournalEntry->save($con);
             }
             $this->setJournalEntry($this->aJournalEntry);
         }
         if ($this->aDocument !== null) {
             if ($this->aDocument->isModified() || $this->aDocument->isNew()) {
                 $affectedRows += $this->aDocument->save($con);
             }
             $this->setDocument($this->aDocument);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
示例#12
0
 public function test_file_field_read_and_write()
 {
     $file = new File("/tmp/test.txt");
     $user = User::find_by_email("*****@*****.**");
     $document = new Document();
     $document->user = $user;
     $document->last_modified = new Date();
     $document->file = $file;
     $document->save();
     FuzzyTest::assert_true($file->exists(), "File not written");
     $document = Document::find_by_id($document->id);
     $result = is_a($document->file, "File");
     FuzzyTest::assert_true($result, "File not read correctly");
     $contents = $document->file->read();
     FuzzyTest::assert_equal($contents, "This is the content of the file", "File not read correctly");
 }
示例#13
0
 protected function saveModel($document = false)
 {
     if (Input::get('id')) {
         $document = Document::find(Input::get('id'));
     }
     if (!$document) {
         $document = new Document();
     }
     $document->type = Input::get('type');
     $document->title = Input::get('title');
     $document->description = Input::get('description');
     $document->url = Input::get('url');
     $document->meta = Input::get('meta');
     $document->save();
     return $document;
 }
示例#14
0
 public function add($post, $path)
 {
     $model = new Document();
     $model->setAttributes($post);
     if (!empty($path)) {
         if (empty($post['name'])) {
             $model->name = $path['name'];
         }
         $model->path = $path['path'];
     }
     $model->created_at = time();
     $model->updated_at = time();
     if ($model->save(FALSE)) {
         return TRUE;
     }
     return FALSE;
 }
示例#15
0
 public function executeJustificatif(sfWebRequest $request)
 {
     $note_de_frais = $this->getRoute()->getObject();
     $user = $this->getUser();
     $asso = $note_de_frais->getAsso();
     $this->checkAuthorisation($asso);
     $html = $this->getPartial('noteDeFrais/pdf', compact(array('note_de_frais', 'asso', 'user')));
     $nom = $note_de_frais->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($note_de_frais->getNom());
     $doc = new Document();
     $doc->setNom('Attestation à signer');
     $doc->setAsso($asso);
     $doc->setUser($this->getUser()->getGuardUser());
     $doc->transaction_id = $note_de_frais->transaction_id;
     $doc->setTypeFromSlug('note_de_frais');
     $path = $doc->generatePDF('Note de frais', $nom, $html);
     $doc->save();
     header('Content-type: application/pdf');
     readfile($path);
     return sfView::NONE;
 }
示例#16
0
 /**
  * Store a newly created branch in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Document::$rules, Document::$messsages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $document = new Document();
     $document->employee_id = Input::get('employee');
     $document->document_name = Input::get('type');
     if (Input::hasFile('path')) {
         $file = Input::file('path');
         $name = time() . '-' . $file->getClientOriginalName();
         $file = $file->move('public/uploads/employees/documents/', $name);
         $input['file'] = '/public/uploads/employees/documents/' . $name;
         $document->document_path = $name;
     }
     $document->description = Input::get('desc');
     $document->save();
     Audit::logaudit('Documents', 'create', 'created: ' . $document->type);
     return Redirect::route('documents.index')->withFlashMessage('Employee document successfully uploaded!');
 }
示例#17
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     Yii::app()->bootstrap->registerJS();
     Yii::app()->bootstrap->registerJSBackend();
     $model = new Document();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Document'])) {
         $model->attributes = $_POST['Document'];
         if ($model->image != "") {
             $docImages = explode('/', $model->image);
             $getInstall = end($docImages);
             $model->image = $getInstall;
         }
         $model->datecreate = date_create()->format('Y-m-d H:i:s');
         $model->usercreate = Yii::app()->user->id;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#18
0
 public function testSaveAndGet_document_name()
 {
     error_reporting(E_ERROR | E_PARSE);
     $document = new Document();
     $document->filename = 'test';
     $document->file_url = 'test_url';
     $document->file_url_noimage = 'test_image_url';
     $document->last_rev_created_name = 'test';
     $document->category_id = '1';
     $document->subcategory_id = '1';
     $document->document_name = 'test';
     $document->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($document->id));
     $this->assertEquals(36, strlen($document->id));
     //execute Get_document_name() method and verify it gets the name correctly
     $this->assertEquals(null, $document->get_document_name(1));
     $this->assertEquals('test', $document->get_document_name($document->id));
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $document->mark_deleted($document->id);
     $result = $document->retrieve($document->id);
     $this->assertEquals(null, $result);
 }
示例#19
0
 public function reportPageGenerator()
 {
     //$action_selection = Former::select( Config::get('kickstart.actionselection'))->name('action');
     $heads = $this->heads;
     $fields = $this->fields;
     $this->ajaxsource = is_null($this->ajaxsource) ? strtolower($this->controller_name) : $this->ajaxsource;
     $this->addurl = is_null($this->addurl) ? strtolower($this->controller_name) . '/add' : $this->addurl;
     $this->importurl = is_null($this->importurl) ? strtolower($this->controller_name) . '/import' : $this->importurl;
     $this->rowdetail = is_null($this->rowdetail) ? strtolower($this->controller_name) . '.rowdetail' : $this->rowdetail;
     $this->delurl = is_null($this->delurl) ? strtolower($this->controller_name) . '/del' : $this->delurl;
     $this->newbutton = is_null($this->newbutton) ? Str::singular($this->controller_name) : $this->newbutton;
     //dialog related url
     //$this->product_info_url = (is_null($this->product_info_url))? strtolower($this->controller_name).'/info': $this->product_info_url;
     $this->prefix = is_null($this->prefix) ? strtolower($this->controller_name) : $this->prefix;
     $select_all = Former::checkbox()->name('All')->check(false)->id('select_all');
     // add selector and sequence columns
     $start_index = -1;
     if ($this->place_action == 'both' || $this->place_action == 'first') {
         array_unshift($heads, array('Actions', array('sort' => false, 'clear' => true, 'class' => 'action')));
         array_unshift($fields, array('', array('sort' => false, 'clear' => true, 'class' => 'action')));
     }
     if ($this->show_select == true) {
         array_unshift($heads, array($select_all, array('sort' => false)));
         array_unshift($fields, array('', array('sort' => false)));
     } else {
         $start_index = $start_index + 1;
     }
     array_unshift($heads, array('#', array('sort' => false)));
     array_unshift($fields, array('', array('sort' => false)));
     // add action column
     if ($this->place_action == 'both') {
         array_push($heads, array('Actions', array('search' => false, 'sort' => false, 'clear' => true, 'class' => 'action')));
         array_push($fields, array('', array('search' => false, 'sort' => false, 'clear' => true, 'class' => 'action')));
     }
     $disablesort = array();
     for ($s = 0; $s < count($heads); $s++) {
         if ($heads[$s][1]['sort'] == false) {
             $disablesort[] = $s;
         }
     }
     $disablesort = implode(',', $disablesort);
     /* additional features */
     $this->dlxl = is_null($this->dlxl) ? strtolower($this->controller_name) . '/dlxl' : $this->dlxl;
     $this->printlink = is_null($this->printlink) || $this->printlink == '' ? strtolower($this->controller_name) . '/print' : $this->printlink;
     $this->pdflink = is_null($this->pdflink) || $this->pdflink == '' ? strtolower($this->controller_name) . '/genpdf' : $this->pdflink;
     $this->xlslink = is_null($this->xlslink) || $this->xlslink == '' ? strtolower($this->controller_name) . '/genxls' : $this->xlslink;
     /*
     if($this->report_entity == false){
     
     }else{
         $this->report_entity = (is_null($this->report_entity) || $this->report_entity == '')? strtolower($this->controller_name): $this->report_entity;
     
         if($this->doc_number == false){
             $sequencer = new Sequence();
             $this->doc_number = $sequencer->getNewId($this->report_entity);
         }
     }
     */
     $html = View::make($this->report_view)->with('title', $this->title)->with('report_data', $this->report_data)->with('newbutton', $this->newbutton)->with('disablesort', $disablesort)->with('addurl', $this->addurl)->with('importurl', $this->importurl)->with('ajaxsource', URL::to($this->ajaxsource))->with('ajaxdel', URL::to($this->delurl))->with('ajaxdlxl', URL::to($this->dlxl))->with('crumb', $this->crumb)->with('printlink', $this->printlink)->with('pdflink', $this->pdflink)->with('xlslink', $this->xlslink)->with('can_add', $this->can_add)->with('is_report', $this->is_report)->with('report_action', $this->report_action)->with('doc_number', $this->doc_number)->with('is_additional_action', $this->is_additional_action)->with('additional_action', $this->additional_action)->with('additional_filter', $this->additional_filter)->with('js_additional_param', $this->js_additional_param)->with('modal_sets', $this->modal_sets)->with('tables', $this->table_raw)->with('table_dnd', $this->table_dnd)->with('table_dnd_url', $this->table_dnd_url)->with('table_dnd_idx', $this->table_dnd_idx)->with('table_group', $this->table_group)->with('table_group_field', $this->table_group_field)->with('table_group_idx', $this->table_group_idx)->with('table_group_collapsible', $this->table_group_collapsible)->with('js_table_event', $this->js_table_event)->with('column_styles', $this->column_styles)->with('additional_page_data', $this->additional_page_data)->with('additional_table_param', $this->additional_table_param)->with('product_info_url', $this->product_info_url)->with('prefix', $this->prefix)->with('heads', $heads)->with('fields', $fields)->with('start_index', $start_index)->with('row', $this->rowdetail)->with('pdf', $this->pdf);
     /*
     PDF::loadHTML($html->render())->setPaper('a4')
              ->setOrientation('landscape')
              ->setOption('margin-bottom', 0)
              ->save($this->report_file_path.$this->report_file_name);
     */
     if ($this->report_file_name) {
         file_put_contents($this->report_file_path . $this->report_file_name, $html);
         $sd = new Document();
         $sd->timestamp = new MongoDate();
         $sd->type = $this->report_type;
         $sd->fullpath = $this->report_file_path . $this->report_file_name;
         $sd->filename = $this->report_file_name;
         $sd->creator_id = Auth::user()->_id;
         $sd->creator_name = Auth::user()->fullname;
         $sd->save();
     }
     if ($this->pdf == true) {
         $html->render();
         $snappy = App::make('snappy.pdf');
         return PDF::loadHTML($html)->setPaper('a4')->setOrientation('landscape')->setOption('margin-bottom', 0)->stream($this->report_file_name);
     }
     if ($this->xls == true) {
         $tables = $this->table_raw;
         $heads = $this->additional_filter;
         Excel::create($this->report_file_name, function ($excel) use($tables, $heads) {
             $excel->sheet('New sheet', function ($sheet) use($tables, $heads) {
                 $xls_view = 'tables.xls';
                 $sheet->loadView($xls_view)->with('heads', $heads)->with('tables', $tables);
             });
         })->download('xls');
     } else {
         return $html;
     }
 }
示例#20
0
    $r = array();
    foreach ($_REQUEST as $i => $v) {
        $r[join('.', explode('_', $i))] = $v;
        //convert _ back to .
    }
    $type = @$r['0'];
    $case = array();
    for ($i0 = 0; isset($r['1.' . $i0]); $i0++) {
        $case[$i0] = array('id' => @$r['1.' . $i0 . ''], 'area of law' => @$r['1.' . $i0 . '.0']);
        $case[$i0]['type of case'] = array();
        for ($i1 = 0; isset($r['1.' . $i0 . '.1.' . $i1]); $i1++) {
            $case[$i0]['type of case'][$i1] = @$r['1.' . $i0 . '.1.' . $i1 . ''];
        }
    }
    $Document = new Document($ID, $type, $case);
    if ($Document->save() !== false) {
        die('ok:' . $_SERVER['PHP_SELF'] . '?Document=' . urlencode($Document->getId()));
    } else {
        die('');
    }
    exit;
    // do not show the interface
}
$buttons = "";
if (isset($_REQUEST['new'])) {
    $new = true;
} else {
    $new = false;
}
if (isset($_REQUEST['edit']) || $new) {
    $edit = true;
示例#21
0
 foreach ($postlist as $variable) {
     if ($variable != "submit") {
         ${$variable} = $_POST[$variable];
     }
 }
 //print_r($_POST);
 if (!empty($_FILES)) {
     foreach ($_FILES as $key => $file) {
         if ($file['error'] != 4) {
             $document = new Document();
             if ($document->attach_file($file)) {
                 $document->idApartament = $idApartament;
                 $detalii = "Detalii" . $key;
                 $document->Detalii = ${$detalii};
                 //print_r($document);
                 if ($document->save()) {
                     $message .= "";
                 } else {
                     foreach ($document->errors as $error) {
                         $message .= $error . "(" . $file['name'] . ");";
                     }
                 }
             } else {
                 foreach ($document->errors as $error) {
                     $message .= $error . "(" . $file['name'] . ");";
                 }
             }
         }
     }
 }
 if ($message == "") {
     $license = new License(new NamedArguments(array('primaryKey' => $licenseID)));
     //remove licenses removes all children data as well
     try {
         $license->removeLicense();
         echo "License successfully deleted.";
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     break;
     //archives (expires) document - defaults to current date/time
 //archives (expires) document - defaults to current date/time
 case 'archiveDocument':
     $document = new Document(new NamedArguments(array('primaryKey' => $_GET['documentID'])));
     $document->expirationDate = date('Y-m-d H:i:s');
     try {
         $document->save();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     break;
     //verify that the new document name doesn't have bad characters and the name isn't already being used
 //verify that the new document name doesn't have bad characters and the name isn't already being used
 case 'checkUploadDocument':
     $uploadDocument = $_POST['uploadDocument'];
     $document = new Document();
     $exists = 0;
     if (!is_writable("documents")) {
         echo 3;
         break;
     }
     //first check that it doesn't have any offending characters
示例#23
0
 public function save($set = null)
 {
     parent::save($set);
     if ($this->isOfficial()) {
         $this->load->model('SeasonRepository', '_season');
         $season = $this->_season->findOneById($this->getId());
         $season->unsetSource();
         $season->unsetId();
         if ($season->getIsTeam()) {
             $team = $season->getTeam();
             $season->unsetTeam();
             $team->addSeason($season, true);
             $team->save();
         }
         if ($season->getIsPlayer()) {
             $player = $season->getPlayer();
             $season->unsetPlayer();
             $player->addSeason($season, true);
             $player->save();
         }
     }
     return $this;
 }
示例#24
0
 function envoyerAction()
 {
     $this->view->doc = $d = $this->_helper->Document(false);
     if ($d) {
         $this->metas(array('DC.Title' => 'Éditer'));
         $this->view->unite = $unite = $d->findUnite();
     } else {
         $this->view->unite = $unite = $this->_helper->Unite(false);
         $this->branche->append('Documents', array('action' => 'index'));
         $this->metas(array('DC.Title' => 'Envoyer un document', 'DC.Title.alternative' => 'Envoyer'));
         $this->branche->append();
     }
     $t = new Unites();
     $unites = $t->fetchAll();
     $envoyables = array();
     foreach ($unites as $u) {
         if ($this->assert(null, $u, 'envoyer-document')) {
             $envoyables[$u->id] = $u->getFullName();
         }
     }
     if (!count($envoyables)) {
         throw new Strass_Controller_Action_Exception_Forbidden("Vous n'avez le droit d'envoyer de document pour aucune unité");
     }
     $this->view->model = $m = new Wtk_Form_Model('envoyer');
     $m->addNewSubmission('envoyer', "Envoyer");
     $m->addEnum('unite', "Unité", $unite->id, $envoyables);
     $i = $m->addString('titre', "Titre", $d ? $d->titre : null);
     $m->addConstraintRequired($i);
     $m->addString('auteur', "Auteur", $d ? $d->auteur : null);
     $m->addDate('date', "Date", $d ? $d->date : strftime('%F %T'));
     $m->addString('description', "Description", $d ? $d->description : null);
     $i = $m->addInstance('File', 'fichier', "Fichier");
     if (!$d) {
         $m->addConstraintRequired($i);
     }
     if ($m->validate()) {
         $t = new Documents();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             if ($d) {
                 $message = "Document modifié";
                 $du = $d->findDocsUnite()->current();
             } else {
                 if (!$d) {
                     $message = "Document envoyé";
                     $d = new Document();
                     $du = new DocUnite();
                 }
             }
             $d->slug = $t->createSlug(wtk_strtoid($m->titre), $d->slug);
             $d->titre = $m->titre;
             $d->auteur = $m->auteur;
             $d->date = $m->date;
             $d->description = $m->description;
             if ($i->isUploaded()) {
                 $d->suffixe = strtolower(end(explode('.', $m->fichier['name'])));
                 $d->save();
                 $d->storeFile($i->getTempFilename());
             } else {
                 $d->save();
             }
             $du->document = $d->id;
             $du->unite = $m->unite;
             $du->save();
             $this->logger->info($message, $this->_helper->Url('index', null, null, array('unite' => $du->findParentUnites()->slug), true));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('details', null, null, array('document' => $d->slug));
     }
 }
示例#25
0
 function envoyerAction()
 {
     if ($this->_getParam('article')) {
         $a = $this->_helper->Article();
         $j = $a->findParentJournaux();
         $c = $a->findParentCommentaires();
         try {
             $d = $a->findDocument();
         } catch (Strass_Db_Table_NotFound $e) {
             $this->redirectSimple('ecrire');
         }
         $message = "Article édité";
     } else {
         $a = null;
         $j = $this->_helper->Journal();
         $message = "Article envoyé";
     }
     $this->metas(array('DC.Title' => "Envoyer"));
     $this->branche->append();
     if ($a) {
         $this->assert(null, $a, null, "Vous n'avez pas le droit d'éditer " . $a);
     } else {
         $this->assert(null, $j, null, "Vous n'avez pas le droit d'envoyer un PDF dans " . $j);
     }
     $this->view->unite = $u = $j->findParentUnites();
     $publier = $this->assert(null, $j, 'publier');
     $this->view->model = $m = new Wtk_Form_Model('envoyer');
     $me = Zend_Registry::get('individu');
     if ($publier) {
         $i = $m->addEnum('auteur', "Auteur");
         /* on inclus les membres de sous-unité : le scout peuvent écrire
            dans la gazette de troupe */
         foreach ($u->findInscrits(null, 1) as $individu) {
             $i->addItem($individu->id, $individu->getFullname(false));
         }
         if (!count($i)) {
             throw new Strass_Controller_Action_Exception_Notice("L'auteur de l'article doit être un membre, mais cette unité n'a aucun membre !");
         }
         if ($a) {
             $i->set($a->findAuteur()->id);
         } else {
             $i->set($me->id);
         }
     } else {
         $i = $m->addInteger('auteur', "Auteur", $me->id, true);
     }
     $i = $m->addInstance('File', 'fichier', "Fichier");
     if (!$a) {
         $m->addConstraintRequired($i);
     }
     $i = $m->addString('titre', "Titre", $a ? $a->titre : null);
     $m->addConstraintRequired($i);
     $m->addDate('date', 'Date', $a ? $c->date : null);
     if ($publier) {
         $m->addEnum('public', 'Publication', $a ? $a->public : null, array(0 => 'Brouillon', 1 => 'Publier'));
     }
     $m->addNewSubmission('envoyer', "Envoyer");
     if ($m->validate()) {
         $td = new Documents();
         $db = $td->getAdapter();
         $db->beginTransaction();
         try {
             $da = (bool) $a;
             if (!$a) {
                 $a = new Article();
                 $c = new Commentaire();
                 $d = new Document();
             }
             $d->slug = $td->createSlug($j->slug . '-' . $m->titre, $d->slug);
             $d->titre = $m->titre;
             $d->date = $m->date;
             $i = $m->getInstance('fichier');
             if ($i->isUploaded()) {
                 $d->suffixe = strtolower(end(explode('.', $m->fichier['name'])));
                 $d->storeFile($i->getTempFilename());
             }
             $d->save();
             $c->auteur = $m->auteur;
             $c->date = $m->date;
             $c->save();
             $a->slug = $a->getTable()->createSlug($m->titre, $a->slug);
             $a->journal = $j->id;
             $a->titre = $m->titre;
             $a->article = '!document';
             try {
                 $a->public = (int) $m->public;
             } catch (Exception $e) {
             }
             $a->commentaires = $c->id;
             $a->save();
             if (!$da) {
                 $da = new DocArticle();
                 $da->article = $a->id;
                 $da->document = $d->id;
                 $da->save();
             }
             $this->logger->info($message, $this->_helper->url('consulter', 'journaux', null, array('article' => $a->slug), true));
             if (!$this->assert(null, $j, 'publier')) {
                 $mail = new Strass_Mail_Article($a);
                 $mail->send();
             }
             $this->_helper->Flash->info($message);
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('consulter', 'journaux', null, array('article' => $a->slug), true);
     }
 }
示例#26
0
 $licenseFile = fopen("documents/" . $filename . ".html", "wb") or die(_("Unable to create file for license."));
 fwrite($licenseFile, "<html>\n<head>\n<meta charset='utf-8'/>\n</head>\n</body>");
 fwrite($licenseFile, $licenseAgreement);
 fwrite($licenseFile, "</body>\n</html>");
 fclose($licenseFile);
 $licenseObj = new License();
 $licenseObj->shortName = $filename;
 $licenseObj->setOrganization($_POST['organizationID'], $_POST['organizationName']);
 $licenseObj->save();
 $licenseID = $licenseObj->primaryKey;
 $documentObj = new Document();
 $documentObj->shortName = $filename;
 $documentObj->documentTypeID = 3;
 $documentObj->licenseID = $licenseID;
 $documentObj->documentURL = $filename . ".html";
 $documentObj->save();
 $documentID = $documentObj->primaryKey;
 if ($_POST['usageTerms'] === "on") {
     foreach ($xml->UsageTerms->Usage as $usage) {
         //get the expressionTypeID -- create expressionType if necessary
         $expression = preg_replace('/^onixPL\\:/s', '', $usage->UsageType);
         $index = searchForShortName($expression, $expressionTypeArray);
         if ($index !== null) {
             $expressionTypeID = $expressionTypeArray[$index]['expressionTypeID'];
             $expressionTypeObj = new ExpressionType(new NamedArguments(array('primaryKey' => $expressionTypeID)));
         } else {
             $expressionTypeObj = new ExpressionType();
             $expressionTypeObj->shortName = $expression;
             $expressionTypeObj->noteType = "Internal";
             $expressionTypeObj->save();
             $expressionTypeID = $expressionTypeObj->primaryKey;
 public function createPdf($productCatalog)
 {
     global $timedate;
     global $app_list_strings;
     global $current_user;
     global $sugar_config;
     $catalog_done = true;
     $create_new_document = true;
     $document = new Document();
     if (!$document->retrieve($productCatalog->document_id)) {
         //$create_new_document = true;
         if (!empty($productCatalog->pdf_document_name)) {
             $document_name = $productCatalog->pdf_document_name;
         } else {
             $document_name = $app_list_strings['oqc']['pdf']['common']['filenamePrefixCatalog'] . "_" . date("Y");
             // Configure default Catalog document name here
         }
     } else {
         // Search is there exist catalog with the same name
         $productCatalog->load_relationship('documents');
         $linkedDocuments = $productCatalog->documents->get();
         //$GLOBALS['log']->error('OQCProductCatalog: Linked documents: '. var_export($linkedDocuments, true));
         if (empty($productCatalog->pdf_document_name)) {
             $document_name = $app_list_strings['oqc']['pdf']['common']['filenamePrefixCatalog'] . "_" . date("Y");
         } else {
             $document_name = $productCatalog->pdf_document_name;
         }
         foreach ($linkedDocuments as $id) {
             if ($document->retrieve($id)) {
                 if ($document->document_name == $document_name) {
                     $create_new_document = false;
                     break;
                 }
             }
         }
     }
     if ($create_new_document) {
         unset($document);
         $document = new Document();
         $document->document_name = $document_name;
         $document->category_id = "ProductCatalog";
         $document->subcategory_id = "Pdf";
         $document->status_id = "Active";
         $document->document_purpose_c = "Internal";
         $document->active_date = date($timedate->get_date_format());
         $document->assigned_user_id = $current_user->id;
         // create an id for this new document
         $document->save();
         $document->new_with_id = false;
     }
     $catalog_done = $this->createNewRevision($productCatalog, $document);
     if ($catalog_done) {
         $productCatalog->load_relationship('documents');
         $productCatalog->documents->add($document->id);
         $productCatalog->document_id = $document->id;
         $productCatalog->save();
         $document->save();
         header("Location: index.php?action=DetailView&module=DocumentRevisions&record={$document->document_revision_id}");
         exit;
     } else {
         if (!$productCatalog->document_id) {
             $document->mark_deleted($document->id);
             //This was new document, so delete it if pdf creation fails
         }
         echo "<html>\n\t\t\tPdf creation failed. Set debugPdfCreation=1 in config file and re-run creation of pdf file to get error log. </br>\n\t\t\t<a href=\"{$sugar_config['site_url']}/index.php?action=DetailView&module=oqc_ProductCatalog&record={$productCatalog->id}\">Return to previuos page</a>\n\t\t\t</html>";
         exit;
     }
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aLanguage !== null) {
             if ($this->aLanguage->isModified() || $this->aLanguage->isNew()) {
                 $affectedRows += $this->aLanguage->save($con);
             }
             $this->setLanguage($this->aLanguage);
         }
         if ($this->aDocumentation !== null) {
             if ($this->aDocumentation->isModified() || $this->aDocumentation->isNew()) {
                 $affectedRows += $this->aDocumentation->save($con);
             }
             $this->setDocumentation($this->aDocumentation);
         }
         if ($this->aDocument !== null) {
             if ($this->aDocument->isModified() || $this->aDocument->isNew()) {
                 $affectedRows += $this->aDocument->save($con);
             }
             $this->setDocument($this->aDocument);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             // Rewind the body LOB column, since PDO does not rewind after inserting value.
             if ($this->body !== null && is_resource($this->body)) {
                 rewind($this->body);
             }
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 public function actionCreate()
 {
     $this->forcePostRequest();
     $_POST = Yii::app()->input->stripClean($_POST);
     $poll = new Document();
     $poll->content->populateByForm();
     $poll->name = Yii::app()->request->getParam('name');
     $poll->body = Yii::app()->request->getParam('body');
     $poll->folder_id = (int) Yii::app()->request->getParam('selectFolder');
     //$poll->allow_multiple = Yii::app()->request->getParam('allowMultiple');
     if ($poll->validate()) {
         $poll->save();
         $this->renderJson(array('wallEntryId' => $poll->content->getFirstWallEntryId()));
     } else {
         $this->renderJson(array('errors' => $poll->getErrors()), false);
     }
 }
 /**
  * Add an order for display
  *
  * @param string $passkey
  * @param string $strId
  * @param int $intDttDate
  * @param int $intDttDue
  * @param string $strPrintedNotes
  * @param string $strStatus
  * @param string $strEmail
  * @param string $strPhone
  * @param string $strZipcode
  * @param int $intTaxcode
  * @param float $fltShippingSell
  * @param float $fltShippingCost
  * @return string
  */
 public function add_order($passkey, $strId, $intDttDate, $intDttDue, $strPrintedNotes, $strStatus, $strEmail, $strPhone, $strZipcode, $intTaxcode, $fltShippingSell, $fltShippingCost)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     $objDocument = Document::LoadByIdStr($strId);
     if (!$objDocument instanceof Document) {
         $objDocument = new Document();
     } else {
         // if cart already exists then delete the items
         foreach ($objDocument->documentItems as $item) {
             $item->qty = 0;
             $item->save();
             $item->product->SetAvailableInventory();
             $item->delete();
         }
     }
     $objDocument->order_type = CartType::order;
     $objDocument->order_str = $strId;
     $objDocument->printed_notes = $strPrintedNotes;
     $objDocument->datetime_cre = date("Y-m-d H:i:s", trim($intDttDate));
     $objDocument->datetime_due = date("Y-m-d H:i:s", trim($intDttDue));
     $objDocument->fk_tax_code_id = $intTaxcode ? $intTaxcode : 0;
     $objDocument->status = $strStatus;
     $objCustomer = Customer::LoadByEmail($strEmail);
     if ($objCustomer instanceof Customer) {
         $objDocument->customer_id = $objCustomer->id;
     }
     $objCart = Cart::LoadByIdStr($strId);
     if ($objCart instanceof Cart) {
         $objDocument->cart_id = $objCart->id;
     }
     $objDocument->status = $strStatus;
     if (!$objDocument->save()) {
         Yii::log("SOAP ERROR : add_order " . print_r($objDocument->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR;
     }
     if ($objCart instanceof Cart) {
         $objCart->document_id = $objDocument->id;
         $objCart->save();
     }
     if (substr($strId, 0, 3) == "WO-") {
         Configuration::SetHighestWO();
     }
     return self::OK;
 }