Ejemplo n.º 1
0
    public function actionRotate(){

        $result['success'] = false;

        if(Yii::app()->request->isAjaxRequest && $_POST['docID']){

            // start profiling
            //xhprof_enable(XHPROF_FLAGS_MEMORY);

            $doc_id= intval($_POST['docID']);

            $rotate_direction=strval ($_POST['action']);

            if ($doc_id > 0 && Documents::hasAccess($doc_id)) {

                                     $return_array=FileModification::prepareFile($doc_id);

                if($return_array['ext']!='pdf'){
                    $return_array = FileModification::ImageToPdf($return_array['path_to_dir'],$return_array['filename'],$return_array['ext']);
                }

                if(!$result['error']) {
                    $result=FileModification::rotateFile($return_array['path_to_dir'],$return_array['filename'],$rotate_direction);
                    $result['success'] = true;
                } else {
                    $result['success'] = false;
                    $result['error_message'] = "File was not rendered.";
                }


                if(!$result['error']) {
                $return_array = FileModification::writeToBase($return_array['path_to_dir'],$return_array['filename'],'application/pdf',$doc_id);

                    $result['file_id'] = FileCache::updateFileInCache($doc_id);

                    $result['success'] = true;

                } else {
                    $result['success'] = false;
                    $result['error_message'] = "File was not rendered.";
                }


            }

            // stop profiler
           /* $xhprof_data = xhprof_disable();
            include_once "/usr/share/php/xhprof_lib/utils/xhprof_lib.php";
            include_once "/usr/share/php/xhprof_lib/utils/xhprof_runs.php";
            $xhprof_runs = new XHProfRuns_Default();
            $run_id = $xhprof_runs->save_run($xhprof_data, "filemodification");
            */

        }

        echo CJSON::encode($result);
    }
Ejemplo n.º 2
0
    public static  function LogAction ($doc_id,$event_type) {

        $ucl =UsersClientList::model()->findByAttributes(array(
            'User_ID' => Yii::app()->user->userID,
            'Client_ID' => Yii::app()->user->clientID,
        ));

        $audit = new Audits();
        $audit->Document_ID = $doc_id;
        $audit->Event_Type = $event_type;
        $audit->Event_User_ID = Yii::app()->user->userID;
        $audit->User_Appr_Value = $ucl->User_Approval_Value;
        $audit->Event_Date = date("Y-m-d H:i:s");
        $audit->save();


        //list of actions that cause update of FileCache

        $events_for_cashe_update = array(self::ACTION_PDF,self::ACTION_REPDF,self::ACTION_REVERT,self::ACTION_REUPLOAD,self::ACTION_ROTATE);

        if (in_array($event_type,$events_for_cashe_update)) {
            FileCache::updateFileInCache($doc_id);
        }


    }
Ejemplo n.º 3
0
    protected function generate_response($content, $print_response = true) {
        if ($print_response) {

            //replace values with modified after file conversion
            foreach ($content['files'] as $file_item) {
                $file_item->url='';
                $file_item->thumbnailUrl='';
                $file_item->path= FileCache::updateFileInCache($file_item->path);

                $new_file_name = FileModification::getFileNameByPath(FileCache::getCacheFilePath($file_item->path));
                if ($new_file_name)  $file_item->name = $new_file_name ;

                //$new_file_ext = FileModification::getFileExtByPath(FileCache::getCacheFilePath($file_item->path));
                $file_item->type = 'application/pdf' ;

                $newcontent['files'][] = $file_item;
            }

            $content = $newcontent;
            $json = json_encode($content);
            $redirect = isset($_REQUEST['redirect']) ?
                stripslashes($_REQUEST['redirect']) : null;
            if ($redirect) {
                $this->header('Location: '.sprintf($redirect, rawurlencode($json)));
                return;
            }
            $this->head();
            if ($this->get_server_var('HTTP_CONTENT_RANGE')) {
                $files = isset($content[$this->options['param_name']]) ?
                    $content[$this->options['param_name']] : null;
                if ($files && is_array($files) && is_object($files[0]) && $files[0]->size) {
                    $this->header('Range: 0-'.(
                        $this->fix_integer_overflow(intval($files[0]->size)) - 1
                    ));
                }
            }
            $this->body($json);
        }
        return $content;
    }