Exemplo n.º 1
0
 function getSubModel()
 {
     if (!$this->SubModel) {
         if (preg_match('/^(.+)_id$/', $this->fieldname, $match)) {
             $alias = Inflector::Classify($match[1]);
             if (!empty($this->Model->{$alias})) {
                 $this->SubModel = $this->Model->{$alias};
             }
         }
     }
     return $this->SubModel;
 }
Exemplo n.º 2
0
 function load($editor = null, $field = null, $config = array())
 {
     switch ($editor) {
         case 'text':
             return $this->text($field);
             break;
     }
     // switch
     $editor = Inflector::Classify($editor);
     if (!App::import('Helper', $editor, true, array(dirname(dirname(dirname(dirname(__FILE__)))) . DS . 'wysiwyg' . DS . 'webroot' . DS . 'js'))) {
         return $this->input($field, array('style' => 'width:98%; height:500px;', 'value' => sprintf(__('%s was not found', true), $editor)));
     }
     $helper = $editor . 'Helper';
     $this->_Editor = new $helper();
     $fields = explode('.', $field);
     $heading = '<h3>' . __(ucfirst(isset($fields[1]) ? $fields[1] : $fields[0])) . '</h3>';
     return $this->input($field, array('label' => false)) . $this->_Editor->editor($field, $config);
 }
Exemplo n.º 3
0
 public function load($editor = null, $field = null, $config = array())
 {
     $helperName = sprintf('Wysiwyg%s', Inflector::Classify($editor));
     switch ($editor) {
         case 'text':
         case CakePlugin::loaded($helperName) == false:
             return $this->text($field);
             break;
     }
     // switch
     try {
         App::uses($helperName . 'Helper', $helperName . '.View/Helper');
         $this->Editor = $this->_View->Helpers->load($helperName . '.' . $helperName);
     } catch (MissingHelperException $e) {
         return $this->input($field, array('style' => 'width:98%; height:500px;')) . $e->getMessage();
     }
     $fields = explode('.', $field);
     $heading = '<div><h3>' . __(ucfirst(isset($fields[1]) ? $fields[1] : $fields[0])) . '</h3>';
     return $heading . $this->input($field, array('label' => false)) . $this->Editor->editor($field, $config) . '</div>';
 }
Exemplo n.º 4
0
Arquivo: Mi.php Projeto: razzman/mi
 /**
  * objects method
  *
  * @param mixed $type
  * @static
  * @return void
  * @access public
  */
 static function objects($type)
 {
     $params = func_get_args();
     unset($params[0]);
     $function = Inflector::pluralize(Inflector::Classify($type));
     $function[0] = strtolower($function[0]);
     return call_user_func_array(array('Mi', $function), $params);
 }
Exemplo n.º 5
0
Arquivo: mi.php Projeto: hiromi2424/mi
 /**
  * main method
  *
  * @access public
  * @return void
  */
 public function main()
 {
     $shortKeys = array('e' => 'exclude');
     foreach ($this->params as $key => $value) {
         if (in_array($key, array('app', 'root', 'working'))) {
             continue;
         }
         if (isset($shortKeys[$key])) {
             $key = $shortKeys[$key];
         }
         if (isset($this->{$key}) && is_array($this->{$key})) {
             $value = explode(',', $value);
         }
         $this->{$key} = $value;
     }
     if (!isset($this->args[0])) {
         $this->_choice();
     }
     if (low($this->args[0]) == 'help') {
         $this->help();
         return;
     }
     $function = Inflector::pluralize(Inflector::Classify($this->args[0]));
     $function[0] = low($function[0]);
     unset($this->args[0]);
     $admin = false;
     if ($function == 'actions' && empty($this->args[1]) && !empty($this->args[2]) && $this->args[2] == 'admin') {
         $this->args = array();
         $admin = true;
     }
     if (!class_exists('Mi')) {
         include_once dirname(dirname(__FILE__)) . DS . 'mi.php';
     }
     if (!$this->args) {
         if ($function == 'actions') {
             $this->_controllers('Actions');
         } elseif ($function == 'views') {
             $this->_controllers('Views');
         } elseif ($function == 'tables') {
             $this->_connections();
         }
     }
     if ($admin) {
         $this->args[] = 'admin';
     }
     $result = call_user_func_array(array('Mi', $function), $this->args);
     $function = Inflector::humanize(Inflector::underscore(Inflector::singularize($function)));
     if (!$result) {
         return;
     }
     if (is_numeric(key($result))) {
         $this->out(str_pad(sprintf(__d('mi', '%1$s Results', true), $function), 50));
         $this->out(str_pad('', 49, '-'));
         foreach ($result as $path => $name) {
             $name = str_pad($name, 50);
             $this->out($name);
         }
         return;
     }
     $this->out(str_pad(sprintf(__d('mi', '%1$s Results', true), $function), 50) . 'Details');
     $this->out(str_pad('', 49, '-') . '|' . str_pad('', 49, '-'));
     foreach ($result as $path => $name) {
         $name = str_pad($name, 50);
         $this->out($name . $path);
     }
 }
Exemplo n.º 6
0
 /**
  * [ADMIN] 固定ページ情報編集
  *
  * @param int $id (page_id)
  * @return void
  * @access public
  */
 function admin_edit($id)
 {
     /* 除外処理 */
     if (!$id && empty($this->data)) {
         $this->Session->setFlash('無効なIDです。');
         $this->redirect(array('action' => 'index'));
     }
     if (empty($this->data)) {
         $this->data = $this->Page->read(null, $id);
         $this->data['Page']['contents_tmp'] = $this->data['Page']['contents'];
         $mobileIds = $this->PageCategory->getAgentCategoryIds('mobile');
         $smartphoneIds = $this->PageCategory->getAgentCategoryIds('smartphone');
         if (in_array($this->data['Page']['page_category_id'], $mobileIds)) {
             $this->data['Page']['page_type'] = 2;
         } elseif (in_array($this->data['Page']['page_category_id'], $smartphoneIds)) {
             $this->data['Page']['page_type'] = 3;
         } else {
             $this->data['Page']['page_type'] = 1;
         }
     } else {
         $before = $this->Page->read(null, $id);
         if (empty($this->data['Page']['page_type'])) {
             $this->data['Page']['page_type'] = 1;
         }
         /* 更新処理 */
         if ($this->data['Page']['page_type'] == 2 && !$this->data['Page']['page_category_id']) {
             $this->data['Page']['page_category_id'] = $this->PageCategory->getAgentId('mobile');
         } elseif ($this->data['Page']['page_type'] == 3 && !$this->data['Page']['page_category_id']) {
             $this->data['Page']['page_category_id'] = $this->PageCategory->getAgentId('smartphone');
         }
         $this->data['Page']['url'] = $this->Page->getPageUrl($this->data);
         $this->Page->set($this->data);
         if ($this->Page->validates()) {
             if ($this->Page->save($this->data, false)) {
                 // タイトル、URL、公開状態が更新された場合、全てビューキャッシュを削除する
                 $beforeStatus = $this->Page->allowedPublish($before['Page']['status'], $before['Page']['publish_begin'], $before['Page']['publish_end']);
                 $afterStatus = $this->Page->allowedPublish($this->data['Page']['status'], $this->data['Page']['publish_begin'], $this->data['Page']['publish_end']);
                 if ($beforeStatus != $afterStatus || $before['Page']['title'] != $this->data['Page']['title'] || $before['Page']['url'] != $this->data['Page']['url']) {
                     clearViewCache();
                 } else {
                     clearViewCache($this->data['Page']['url']);
                 }
                 // 完了メッセージ
                 $message = '固定ページ「' . $this->data['Page']['name'] . '」を更新しました。';
                 $this->Session->setFlash($message);
                 $this->Page->saveDbLog($message);
                 // afterPageEdit
                 $this->executeHook('afterPageEdit');
                 // 同固定ページへリダイレクト
                 $this->redirect(array('action' => 'edit', $id));
             } else {
                 $this->Session->setFlash('保存中にエラーが発生しました。');
             }
         } else {
             $this->Session->setFlash('入力エラーです。内容を修正してください。');
         }
     }
     /* 表示設定 */
     $currentOwnerId = '';
     $currentPageCategoryId = '';
     if (!empty($this->data['PageCategory']['id'])) {
         $currentPageCategoryId = $this->data['PageCategory']['id'];
     }
     $categories = $this->getCategorySource($this->data['Page']['page_type'], array('currentOwnerId' => $currentOwnerId, 'currentPageCategoryId' => $currentPageCategoryId, 'own' => true, 'empty' => '指定しない'));
     $url = $this->convertViewUrl($this->data['Page']['url']);
     if ($this->data['Page']['url']) {
         $this->set('publishLink', $url);
     }
     $this->set('categories', $categories);
     $this->set('editable', $this->checkCurrentEditable($currentPageCategoryId, $currentOwnerId));
     $this->set('previewId', $this->data['Page']['id']);
     $this->set('reflectMobile', Configure::read('BcApp.mobile'));
     $this->set('reflectSmartphone', Configure::read('BcApp.smartphone'));
     $this->set('users', $this->Page->getControlSource('user_id'));
     $this->set('ckEditorOptions1', array('useDraft' => true, 'draftField' => 'draft', 'disableDraft' => false, 'width' => 'auto'));
     $this->set('url', $url);
     $this->set('mobileExists', $this->Page->agentExists('mobile', $this->data));
     $this->set('smartphoneExists', $this->Page->agentExists('smartphone', $this->data));
     $this->set('rootMobileId', $this->PageCategory->getAgentId('mobile'));
     $this->set('rootSmartphoneId', $this->PageCategory->getAgentId('smartphone'));
     $this->subMenuElements = array('pages', 'page_categories');
     if (!empty($this->data['Page']['title'])) {
         $this->pageTitle = '固定ページ情報編集:' . $this->data['Page']['title'];
     } else {
         $this->pageTitle = '固定ページ情報編集:' . Inflector::Classify($this->data['Page']['name']);
     }
     $this->help = 'pages_form';
     $this->render('form');
 }
Exemplo n.º 7
0
<?php

define('ROOT_DIR', dirname(__FILE__));
define('DS', DIRECTORY_SEPARATOR);
require ROOT_DIR . DS . 'include' . DS . 'setup.php';
try {
    if (empty($_REQUEST['c'])) {
        $_REQUEST['c'] = 'newz';
    }
    $controller_name = Inflector::Classify($_REQUEST['c']) . '_Controller';
    $controller_file = Inflector::underscore($_REQUEST['c']);
    include CONTROLLER_DIR . DS . $controller_file . '_controller.php';
    $controller = new $controller_name();
} catch (Exception $e) {
    echo $e;
}
Exemplo n.º 8
0
    public function _missing_table($table = null)
    {
        $tableNotExist = array();
        $tables = array('departments', 'branches', 'designations', 'users', 'employees', 'supplier_registrations', 'products', 'benchmarks');
        foreach ($tables as $table) {
            $modelName = null;
            $modelName .= Inflector::Classify($table);
            $this->loadModel($modelName);
            $this->{$modelName}->recursive = -1;
            $tableExist = $this->{$modelName}->find('first', array('conditions' => array('publish' => 1)));
            if (empty($tableExist)) {
                $tableNotExist[] = $table;
            }
        }
        if (empty($tableNotExist)) {
            return true;
        } else {
            $this->set('tableNotExist', $tableNotExist);
        }
        $this->set($tableNotExist);
        $this->set('install', true);
        if ($tableNotExist[0] == 'benchmarks') {
            $getLink = Router::url('/', true) . $tableNotExist[0];
        } else {
            $getLink = Router::url('/', true) . $tableNotExist[0] . '/lists';
        }
        $this->Session->setFlash('Please add details for <h4>' . Inflector::Humanize($tableNotExist[0]) . ' <a href="' . $getLink . '" class="btn btn-sm btn-success">Add new</a></h4>
					before you start using the application.You can also import these records if you have them ready. <br />
					<strong>Please not that you will have to publish records which you are importing before you can access those records.</strong>
					<br />List of required tables are  Departments, Branches, Designations, Users, Employees, Suppliers, Devices, Products, Benchmarks');
        if (!in_array($this->params->controller, $tables, true)) {
            if ($tableNotExist[0] == '/benchmarks') {
                $this->redirect(array('controller' => $tableNotExist[0], 'action' => 'index'));
            } else {
                $this->redirect(array('controller' => $tableNotExist[0], 'action' => 'index'));
            }
        }
    }
Exemplo n.º 9
0
 /**
  * [ADMIN] 固定ページ情報編集
  *
  * @param int $id (page_id)
  * @return void
  */
 public function admin_edit($id)
 {
     if (!$id && empty($this->request->data)) {
         $this->setMessage('無効なIDです。', true);
         $this->redirect(['action' => 'index']);
     }
     if (empty($this->request->data)) {
         $this->request->data = $this->Page->read(null, $id);
     } else {
         $isChangedStatus = $this->Content->isChangedStatus($id, $this->request->data);
         if (empty($this->request->data['Page']['page_type'])) {
             $this->request->data['Page']['page_type'] = 1;
         }
         // EVENT Pages.beforeEdit
         $event = $this->dispatchEvent('beforeEdit', ['data' => $this->request->data]);
         if ($event !== false) {
             $this->request->data = $event->result === true ? $event->data['data'] : $event->result;
         }
         $this->Page->set($this->request->data);
         if ($data = $this->Page->save()) {
             // タイトル、URL、公開状態が更新された場合、全てビューキャッシュを削除する
             if ($isChangedStatus) {
                 clearViewCache();
             } else {
                 clearViewCache($this->request->data['Content']['url']);
             }
             // 完了メッセージ
             $this->setMessage('固定ページ「' . $this->request->data['Content']['name'] . '」を更新しました。', false, true);
             // EVENT Pages.afterEdit
             $this->dispatchEvent('afterEdit', ['data' => $data]);
             // 同固定ページへリダイレクト
             $this->redirect(['action' => 'edit', $id]);
         } else {
             $this->setMessage('入力エラーです。内容を修正してください。', true);
         }
     }
     // 公開リンク
     $publishLink = '';
     if ($this->request->data['Content']['url']) {
         $publishLink = $this->request->data['Content']['url'];
     }
     // エディタオプション
     $editorOptions = ['editorDisableDraft' => false];
     if (!empty($this->siteConfigs['editor_styles'])) {
         App::uses('CKEditorStyleParser', 'Vendor');
         $CKEditorStyleParser = new CKEditorStyleParser();
         $editorOptions = array_merge($editorOptions, ['editorStylesSet' => 'default', 'editorStyles' => ['default' => $CKEditorStyleParser->parse($this->siteConfigs['editor_styles'])]]);
     }
     // ページテンプレートリスト
     $pageTemplateList = $this->Page->getPageTemplateList($this->request->data['Content']['id'], $this->siteConfigs['theme']);
     $this->set(compact('editorOptions', 'pageTemplateList', 'publishLink'));
     if (!empty($this->request->data['Content']['title'])) {
         $this->pageTitle = '固定ページ情報編集:' . $this->request->data['Content']['title'];
     } else {
         $this->pageTitle = '固定ページ情報編集:' . Inflector::Classify($this->request->data['Content']['name']);
     }
     $this->help = 'pages_form';
     $this->render('form');
 }
Exemplo n.º 10
0
 /**
  * [ADMIN] 固定ページ情報編集
  *
  * @param int $id (page_id)
  * @return void
  * @access public
  */
 public function admin_edit($id)
 {
     /* 除外処理 */
     if (!$id && empty($this->request->data)) {
         $this->setMessage('無効なIDです。', true);
         $this->redirect(array('action' => 'index'));
     }
     if (empty($this->request->data)) {
         $this->request->data = $this->Page->read(null, $id);
         $mobileIds = $this->PageCategory->getAgentCategoryIds('mobile');
         $smartphoneIds = $this->PageCategory->getAgentCategoryIds('smartphone');
         if (in_array($this->request->data['Page']['page_category_id'], $mobileIds)) {
             $this->request->data['Page']['page_type'] = 2;
         } elseif (in_array($this->request->data['Page']['page_category_id'], $smartphoneIds)) {
             $this->request->data['Page']['page_type'] = 3;
         } else {
             $this->request->data['Page']['page_type'] = 1;
         }
     } else {
         $before = $this->Page->find('first', array('conditions' => array('Page.id' => $id)));
         if (empty($this->request->data['Page']['page_type'])) {
             $this->request->data['Page']['page_type'] = 1;
         }
         /* 更新処理 */
         if ($this->request->data['Page']['page_type'] == 2 && !$this->request->data['Page']['page_category_id']) {
             $this->request->data['Page']['page_category_id'] = $this->PageCategory->getAgentId('mobile');
         } elseif ($this->request->data['Page']['page_type'] == 3 && !$this->request->data['Page']['page_category_id']) {
             $this->request->data['Page']['page_category_id'] = $this->PageCategory->getAgentId('smartphone');
         }
         $this->request->data['Page']['url'] = $this->Page->getPageUrl($this->request->data);
         /*			 * * Pages.beforeEdit ** */
         $event = $this->dispatchEvent('beforeEdit', array('data' => $this->request->data));
         if ($event !== false) {
             $this->request->data = $event->result === true ? $event->data['data'] : $event->result;
         }
         $this->Page->set($this->request->data);
         if ($this->Page->validates()) {
             if ($data = $this->Page->save(null, false)) {
                 // タイトル、URL、公開状態が更新された場合、全てビューキャッシュを削除する
                 $beforeStatus = $this->Page->isPublish($before['Page']['status'], $before['Page']['publish_begin'], $before['Page']['publish_end']);
                 $afterStatus = $this->Page->isPublish($this->request->data['Page']['status'], $this->request->data['Page']['publish_begin'], $this->request->data['Page']['publish_end']);
                 if ($beforeStatus != $afterStatus || $before['Page']['title'] != $this->request->data['Page']['title'] || $before['Page']['url'] != $this->request->data['Page']['url']) {
                     clearViewCache();
                 } else {
                     clearViewCache($this->request->data['Page']['url']);
                 }
                 // 完了メッセージ
                 $this->setMessage('固定ページ「' . $this->request->data['Page']['name'] . '」を更新しました。', false, true);
                 /*					 * * Pages.afterEdit ** */
                 $this->dispatchEvent('afterEdit', array('data' => $data));
                 // 同固定ページへリダイレクト
                 $this->redirect(array('action' => 'edit', $id));
             } else {
                 $this->setMessage('保存中にエラーが発生しました。', true);
             }
         } else {
             $this->setMessage('入力エラーです。内容を修正してください。', true);
         }
     }
     /* 表示設定 */
     $currentPageCategoryId = '';
     if (!empty($this->request->data['PageCategory']['id'])) {
         $currentPageCategoryId = $this->request->data['PageCategory']['id'];
     }
     if (empty($this->request->data['PageCategory']['id']) || $this->request->data['PageCategory']['name'] == 'mobile' || $this->request->data['PageCategory']['name'] == 'smartphone') {
         $currentCatOwnerId = $this->siteConfigs['root_owner_id'];
     } else {
         $currentCatOwnerId = $this->request->data['PageCategory']['owner_id'];
     }
     $categories = $this->getCategorySource($this->request->data['Page']['page_type'], array('currentOwnerId' => $currentCatOwnerId, 'currentPageCategoryId' => $currentPageCategoryId, 'own' => true, 'empty' => '指定しない'));
     $url = $this->Page->convertViewUrl($this->request->data['Page']['url']);
     if ($this->request->data['Page']['url']) {
         $this->set('publishLink', $url);
     }
     if (Configure::read('BcApp.mobile') && (!isset($this->siteConfigs['linked_pages_mobile']) || !$this->siteConfigs['linked_pages_mobile'])) {
         $reflectMobile = true;
     } else {
         $reflectMobile = false;
     }
     if (Configure::read('BcApp.smartphone') && (!isset($this->siteConfigs['linked_pages_smartphone']) || !$this->siteConfigs['linked_pages_smartphone'])) {
         $reflectSmartphone = true;
     } else {
         $reflectSmartphone = false;
     }
     $editorOptions = array('editorDisableDraft' => false);
     if (!empty($this->siteConfigs['editor_styles'])) {
         App::uses('CKEditorStyleParser', 'Vendor');
         $CKEditorStyleParser = new CKEditorStyleParser();
         $editorStyles = array('default' => $CKEditorStyleParser->parse($this->siteConfigs['editor_styles']));
         $editorOptions = array_merge($editorOptions, array('editorStylesSet' => 'default', 'editorStyles' => $editorStyles));
     }
     $this->set('currentCatOwnerId', $currentCatOwnerId);
     $this->set('categories', $categories);
     $this->set('editable', $this->checkCurrentEditable($currentPageCategoryId, $currentCatOwnerId));
     $this->set('previewId', $this->request->data['Page']['id']);
     $this->set('reflectMobile', $reflectMobile);
     $this->set('reflectSmartphone', $reflectSmartphone);
     $this->set('users', $this->Page->getControlSource('user_id'));
     $this->set('editorOptions', $editorOptions);
     $this->set('url', $url);
     $this->set('mobileExists', $this->Page->agentExists('mobile', $this->request->data));
     $this->set('smartphoneExists', $this->Page->agentExists('smartphone', $this->request->data));
     $this->set('rootMobileId', $this->PageCategory->getAgentId('mobile'));
     $this->set('rootSmartphoneId', $this->PageCategory->getAgentId('smartphone'));
     $this->subMenuElements = array('pages', 'page_categories');
     if (!empty($this->request->data['Page']['title'])) {
         $this->pageTitle = '固定ページ情報編集:' . $this->request->data['Page']['title'];
     } else {
         $this->pageTitle = '固定ページ情報編集:' . Inflector::Classify($this->request->data['Page']['name']);
     }
     $this->help = 'pages_form';
     $this->render('form');
 }
 public function prepare_graph_data($startDate = null, $endDate = null)
 {
     App::import('AppController', 'Controller');
     //get benchmark agevare
     $this->loadModel('Benchmark');
     $agg_benchmarks = $this->Benchmark->find('all', array('conditions' => array('Benchmark.publish' => 1, 'Benchmark.soft_delete' => 0)));
     $i = 0;
     $b = 0;
     foreach ($agg_benchmarks as $benchmark) {
         $b = $b + $benchmark['Benchmark']['benchmark'];
         if ($benchmark['Benchmark']['benchmark'] > 0) {
             $i++;
         }
     }
     if ($i != 0) {
         $benchmark = round($b / $i);
     } else {
         $benchmark = 0;
     }
     $this->loadModel('History');
     App::import('HtmlHelper', 'View/Helper');
     $aControllers = $this->get();
     if ($startDate == null && $endDate == null) {
         $startDate = $this->History->find('first', array('fields' => array('History.created'), 'order' => array('History.created' => 'asc')));
         $endDate = $this->History->find('first', array('fields' => array('History.created'), 'order' => array('History.created' => 'desc')));
         $date = date("Y-m-d", strtotime($startDate['History']['created']));
         $end_date = date("Y-m-d", strtotime($endDate['History']['created']));
         $filedate = date('Y-m-d');
     } else {
         $date = date("Y-m-d", strtotime($startDate));
         $end_date = date("Y-m-d", strtotime($endDate));
         $filedate = date('Y-m-d', strtotime($date));
     }
     $output = array();
     while (strtotime($date) <= strtotime($end_date)) {
         $subCount = 0;
         foreach ($aControllers as $key => $value) {
             if ($key == 'DashboardsController' || $key == 'ErrorsController' || $key == 'InstallerController' || $key == 'PagesController') {
                 continue;
             }
             if ($key !== 'UpdatesController') {
                 $count = 0;
                 $getModelName = Inflector::Classify(str_replace('Controller', '', $key));
                 $this->loadModel($getModelName);
                 $this->{$getModelName}->recursive = -1;
                 if ($getModelName != 'History' && $getModelName != 'UserSession' && $getModelName != 'App' && $getModelName != 'Benchmarks' && $getModelName != 'Page' && $getModelName != 'Dashboard' && $getModelName != 'Error' && $getModelName != 'NotificaionType' && $getModelName != 'Approval' && $getModelName != 'Benchmark' && $getModelName != 'FileUpload' && $getModelName != 'DataEntry' && $getModelName != 'Help' && $getModelName != 'MeetingBranch' && $getModelName != 'MeetingDepartment' && $getModelName != 'MeetingEmployee' && $getModelName != 'MeetingTopic' && $getModelName != 'Message' && $getModelName != 'NotificationUser' && $getModelName != 'PurchaseOrderDetail' && $getModelName != 'NotificationUser' && $getModelName != 'PurchaseOrderDetail' && $getModelName != 'MasterListOfFormatBranch' && $getModelName != 'MasterListOfFormatDepartment' && $getModelName != 'MasterListOfFormatDistributor') {
                     $count = $this->{$getModelName}->find('count', array('conditions' => array($getModelName . '.created BETWEEN ? AND ? ' => array($date . ":00:00:000", $date . ":23:59:000"))));
                     $subCount = $subCount + $count;
                 }
             }
         }
         if ($subCount > 0) {
             $output[] = array('count' => $subCount, 'date' => $date);
         }
         $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
     }
     $data = null;
     $data = "[['Date','Records','Data Entry Benchmark'],";
     foreach ($output as $graph_data) {
         $data .= "['" . date('d-m-Y', strtotime($graph_data['date'])) . "'," . $graph_data['count'] . "," . $benchmark . "],";
     }
     $data .= "]]";
     $data = str_replace("],]]", "]]", $data);
     $folder = new Folder();
     if (isset($_ENV['company_id']) && $_ENV['company_id'] != null) {
         $folder->create(WWW_ROOT . "files" . DS . $_ENV['company_id'] . DS . "graphs" . DS . "departments" . DS . $key, 0777);
         $folder->create(WWW_ROOT . "files" . DS . $_ENV['company_id'] . DS . "graphs" . DS . $filedate, 0777);
         $file = fopen(WWW_ROOT . "files/" . DS . $_ENV['company_id'] . "/graphs/" . $filedate . "/graph_data.txt", "w") or die('can not open file-1');
     } else {
         $folder->create(WWW_ROOT . "files" . DS . $this->Session->read('User.company_id') . DS . "graphs" . DS . "departments" . DS . $key, 0777);
         $folder->create(WWW_ROOT . "files" . DS . $this->Session->read('User.company_id') . DS . "graphs" . DS . $filedate, 0777);
         $file = fopen(WWW_ROOT . "files/" . $this->Session->read('User.company_id') . "/graphs/" . $filedate . "/graph_data.txt", "w") or die('can not open file-2');
     }
     fwrite($file, $data);
     fclose($file);
 }
 public function _check_access($modelName = null)
 {
     $this->loadModel('User');
     $this->User->recursive = 0;
     $userAccess = $this->User->find('first', array('conditions' => array('User.id' => $this->Session->read('User.id')), 'fields' => array('User.user_access')));
     $newData = json_decode($userAccess['User']['user_access'], true);
     if (!$newData) {
         return true;
     } else {
         foreach ($newData['user_access'] as $m) {
             $model = array_keys($m);
             if (Inflector::Singularize(Inflector::Classify($model[0])) == $modelName) {
                 if ($m[$model[0]]['allow'] == true) {
                     return true;
                 } else {
                     return false;
                 }
             }
         }
     }
 }
 public function get_fields($id = null, $noAjax = null)
 {
     if ($noAjax != 'noAjax') {
         $this->layout = 'ajax';
     }
     $form_details = $this->CustomTemplate->MasterListOfFormat->find('first', array('conditions' => array('MasterListOfFormat.id' => $id)));
     $sys_table_name = $form_details['SystemTable']['system_name'];
     $sys_table_name = Inflector::Classify($sys_table_name);
     $this->loadModel($sys_table_name);
     $form_schema = $this->{$sys_table_name}->schema();
     unset($form_schema['id']);
     unset($form_schema['sr_no']);
     unset($form_schema['publish']);
     unset($form_schema['soft_delete']);
     unset($form_schema['branchid']);
     unset($form_schema['departmentid']);
     unset($form_schema['modified_by']);
     unset($form_schema['created_by']);
     unset($form_schema['created']);
     unset($form_schema['modified']);
     unset($form_schema['modified_by']);
     unset($form_schema['system_table_id']);
     unset($form_schema['master_list_of_format_id']);
     $associated_forms = $this->{$sys_table_name}->belongsTo;
     unset($associated_forms['BranchIds']);
     unset($associated_forms['DepartmentIds']);
     unset($associated_forms['SystemTable']);
     foreach ($associated_forms as $associated_form => $values) {
         $this->loadModel($associated_form);
         $associated_form_schemas[$associated_form] = $this->{$associated_form}->schema();
         unset($associated_form_schemas[$associated_form]['id']);
         unset($associated_form_schemas[$associated_form]['sr_no']);
         unset($associated_form_schemas[$associated_form]['publish']);
         unset($associated_form_schemas[$associated_form]['soft_delete']);
         unset($associated_form_schemas[$associated_form]['branchid']);
         unset($associated_form_schemas[$associated_form]['departmentid']);
         unset($associated_form_schemas[$associated_form]['modified_by']);
         unset($associated_form_schemas[$associated_form]['created_by']);
         unset($associated_form_schemas[$associated_form]['created']);
         unset($associated_form_schemas[$associated_form]['modified']);
         unset($associated_form_schemas[$associated_form]['modified_by']);
         unset($associated_form_schemas[$associated_form]['system_table_id']);
         unset($associated_form_schemas[$associated_form]['master_list_of_format_id']);
     }
     $hasMany_forms = $this->{$sys_table_name}->hasMany;
     unset($hasMany_forms['BranchIds']);
     unset($hasMany_forms['DepartmentIds']);
     unset($hasMany_forms['SystemTable']);
     foreach ($hasMany_forms as $hasMany_form => $values) {
         $this->loadModel($hasMany_form);
         $hasMany_form_schemas[$hasMany_form] = $this->{$hasMany_form}->schema();
         unset($hasMany_form_schemas[$hasMany_form]['id']);
         unset($hasMany_form_schemas[$hasMany_form]['sr_no']);
         unset($hasMany_form_schemas[$hasMany_form]['publish']);
         unset($hasMany_form_schemas[$hasMany_form]['soft_delete']);
         unset($hasMany_form_schemas[$hasMany_form]['branchid']);
         unset($hasMany_form_schemas[$hasMany_form]['departmentid']);
         unset($hasMany_form_schemas[$hasMany_form]['modified_by']);
         unset($hasMany_form_schemas[$hasMany_form]['created_by']);
         unset($hasMany_form_schemas[$hasMany_form]['created']);
         unset($hasMany_form_schemas[$hasMany_form]['modified']);
         unset($hasMany_form_schemas[$hasMany_form]['modified_by']);
         unset($hasMany_form_schemas[$hasMany_form]['system_table_id']);
         unset($hasMany_form_schemas[$hasMany_form]['master_list_of_format_id']);
     }
     $this->set(compact('form_details', 'form_schema', 'associated_forms', 'associated_form_schemas', 'sys_table_name', 'hasMany_froms', 'hasMany_form_schemas'));
 }