public function configure()
 {
     $this->useFields(array('state', 'filename'));
     $this->addPagerItems();
     $state_list = Imports::getStateList();
     /* Widgets */
     $this->widgetSchema['state'] = new sfWidgetFormChoice(array('choices' => $state_list));
     $this->widgetSchema['filename'] = new sfWidgetFormInputText();
     $this->widgetSchema['filename']->setAttributes(array('class' => 'small_size'));
     /* Labels */
     $this->widgetSchema->setLabels(array('filename' => 'Filename', 'state' => 'State'));
     /* validators */
     $this->widgetSchema['show_finished'] = new sfWidgetFormInputCheckbox();
     $this->setDefault('show_finished', true);
     $this->validatorSchema['show_finished'] = new sfValidatorBoolean(array('required' => false));
 }
 public function configure()
 {
     $this->useFields(array('collection_ref', 'state', 'filename'));
     $this->addPagerItems();
     $collection_list = Doctrine::getTable('Collections')->getAllAvailableCollectionsFor($this->options['user']);
     $state_list = Imports::getStateList();
     /* Widgets */
     $this->widgetSchema['collection_ref'] = new sfWidgetFormChoice(array('choices' => $collection_list));
     $this->widgetSchema['state'] = new sfWidgetFormChoice(array('choices' => $state_list));
     $this->widgetSchema['filename'] = new sfWidgetFormInputText();
     $this->widgetSchema['filename']->setAttributes(array('class' => 'small_size'));
     /* Labels */
     $this->widgetSchema->setLabels(array('collection_ref' => 'Collections', 'filename' => 'Filename', 'state' => 'State'));
     /* validators */
     $this->validatorSchema['collection_ref'] = new sfValidatorChoice(array('choices' => array_keys($collection_list)));
     $this->widgetSchema['show_finished'] = new sfWidgetFormInputCheckbox();
     $this->validatorSchema['show_finished'] = new sfValidatorBoolean(array('required' => false));
 }
Пример #3
0
 /**
  * Import a set of CSV data into the software.
  *
  * This function is called via AJAX and is the meat of the global import process.
  * It takes the variable "count" as POST data to determine how many records
  * it should import in this step, which is usually 50, but is arbitrary
  * except for server load considerations. It reads data out of the "data.csv"
  * file and imports it. See inline comments for details of what's going on.
  *
  * @return null A return statement to cease further execution, could probably be cleaned up & removed
  */
 public function actionGlobalImport()
 {
     if (isset($_POST['count']) && file_exists($this->safePath())) {
         $metaData = $_SESSION['metaData'];
         // Grab the most recent metadata
         $modelType = $_SESSION['model'];
         // And model
         $count = $_POST['count'];
         $fp = fopen($this->safePath(), 'r+');
         /*
          * THIS IS ESSENTIAL. As with the above block noted as essential,
          * this was KEY to figuring out how to do an AJAX based CSV read.
          * The fseek function will move the file pointer to the specified offset,
          * which we always store in the $_SESSION['offset'] variable.
          */
         fseek($fp, $_SESSION['offset']);
         for ($i = 0; $i < $count; $i++) {
             // Loop up to the speficied count.
             $arr = fgetcsv($fp);
             // Grab the next row
             if ($arr !== false && !is_null($arr)) {
                 while ("" === end($arr)) {
                     // Remove blank space from the end
                     array_pop($arr);
                 }
                 $newType = array_pop($arr);
                 // Pull the last column to check the model type
                 if ($newType != $modelType) {
                     /*
                      * If this is the first row of a new model type, the data
                      * in the last column will be a different class name. In that
                      * case, we assume this new row consists of the metadata
                      * for this new model class and that the next set of records
                      * will be of this model type. This information is stored
                      * in the session in case a set of 50 records breaks
                      * unevenly across model types (e.g. the system needs to import
                      * more than 50 of a given record).
                      */
                     $_SESSION['model'] = $newType;
                     $_SESSION['metaData'] = $arr;
                     $modelType = $_SESSION['model'];
                     $metaData = $_SESSION['metaData'];
                 } else {
                     $attributes = array_combine($metaData, $arr);
                     if ($modelType == "Actions" && (isset($attributes['type']) && $attributes['type'] == 'workflow')) {
                         // In the event that we're importing workflow, we need a special
                         // scenario.
                         $model = new Actions('workflow');
                     } else {
                         $model = new $modelType();
                     }
                     /*
                      * This loops through and sets the attributes manually.
                      * Realistically, this could be refactored to use the
                      * SetX2Fields function, but you'd need to be sure the
                      * data wasn't double formatted (e.g. it's already a unix
                      * timestamp, not a date string, and doesn't need to be
                      * converted again) due to the fact that a user could supply
                      * either human readable or machine readable data.
                      */
                     foreach ($attributes as $key => $value) {
                         if ($model->hasAttribute($key) && isset($value)) {
                             if ($value == "") {
                                 $value = null;
                             }
                             $model->{$key} = $value;
                         }
                     }
                     // Don't make a changelog record.
                     $model->disableBehavior('changelog');
                     // Don't manually set the timestamp fields
                     $model->disableBehavior('X2TimestampBehavior');
                     if ($model instanceof User || $model instanceof Profile) {
                         if ($model->id == '1') {
                             /*
                              * If a model of type User with the ID of one is
                              * being imported skip so that we DO NOT
                              * OVERWRITE THE CURRENT ADMIN USER.
                              */
                             continue;
                         }
                         // Users & Profile normally require special validation, set a scenario for import
                         $model->setScenario('import');
                     }
                     if ($_SESSION['overwrite'] == 1 && property_exists($model, 'subScenario')) {
                         $model->subScenario = 'importOverwrite';
                     }
                     // If an ID was provided, check if there's already a model with that ID
                     $lookup = X2Model::model($modelType)->findByPk($model->id);
                     $lookupFlag = isset($lookup);
                     /*
                      * I'm not sure if "validate" will succeed anymore given the
                      * change made to ID being a "unique" field in X2Model's rules
                      * This should be investigated at some point.
                      */
                     if ($model->validate() || $modelType == "User" || $modelType == 'Profile') {
                         $saveFlag = true;
                         if ($lookupFlag) {
                             if ($_SESSION['overwrite'] == 1) {
                                 // If the user specified to overwrite, delete the old lookup
                                 if ($modelType === "Fields") {
                                     /**
                                      * Leave fields intact; the record information would be deleted when
                                      * the column is removed by Fields' afterDelete hook.
                                      */
                                     continue;
                                 }
                                 $lookup->disableBehavior('changelog');
                                 $lookup->delete();
                             } else {
                                 $saveFlag = false;
                                 // Otherwise, note a failure in the logging section that we were unable to overwrite a record.
                                 isset($_SESSION['overwriteFailure'][$modelType]) ? $_SESSION['overwriteFailure'][$modelType]++ : ($_SESSION['overwriteFailure'][$modelType] = 1);
                             }
                             if (!$model->validate()) {
                                 $saveFlag = false;
                                 $failedImport = fopen($this->safePath('failedImport.csv'), 'a+');
                                 $lastFailed = $_SESSION['lastFailed'];
                                 if ($lastFailed != $modelType) {
                                     $tempMeta = $metaData;
                                     // Keep track of the metadata of failed records
                                     $tempMeta[] = $modelType;
                                     fputcsv($failedImport, $tempMeta);
                                 }
                                 $attr = $model->attributes;
                                 $tempAttributes = X2Model::model($modelType)->attributes;
                                 $attr = array_merge($tempAttributes, $attr);
                                 $attr[] = $modelType;
                                 fputcsv($failedImport, $attr);
                                 $_SESSION['lastFailed'] = $modelType;
                                 // Specify the most recent model type failure in case metadata needs to be changed
                                 isset($_SESSION['failed']) ? $_SESSION['failed']++ : ($_SESSION['failed'] = 1);
                             }
                         }
                         if ($saveFlag && $model->save()) {
                             if ($modelType != "Admin" && !(($modelType == "User" || $modelType == "Profile") && ($model->id == '1' || $model->username == 'api'))) {
                                 // Generate a new "Imports" model in case of rollback
                                 $importLink = new Imports();
                                 $importLink->modelType = $modelType;
                                 $importLink->modelId = $model->id;
                                 $importLink->importId = $_SESSION['importId'];
                                 $importLink->timestamp = time();
                                 $importLink->save();
                             }
                             if ($modelType === "Fields") {
                                 // If we're creating a field, we must also recreate the
                                 // respective table index
                                 if (isset($model->keyType)) {
                                     $model->createIndex($model->keyType === "UNI");
                                 }
                             } else {
                                 if ($modelType === "FormLayout") {
                                     /*
                                      Ensure default form settings are maintained. If overwrite
                                      is set, the most recently imported layout will be set to
                                      default, otherwise the default flags for the newly imported
                                      layout will be cleared.
                                     */
                                     if ($_SESSION['overwrite']) {
                                         if ($model->defaultView) {
                                             FormLayout::clearDefaultFormLayouts('view', $model->model);
                                         }
                                         if ($model->defaultForm) {
                                             FormLayout::clearDefaultFormLayouts('form', $model->model);
                                         }
                                         $model->save();
                                     } else {
                                         $model->defaultView = false;
                                         $model->defaultForm = false;
                                         $model->save();
                                     }
                                 }
                             }
                             // Relic of when action description wasn't a field, not sure if necessary.
                             if ($modelType == 'Actions' && isset($attributes['actionDescription'])) {
                                 $model->actionDescription = $attributes['actionDescription'];
                             }
                             // Update counts in the session logging variables.
                             isset($_SESSION['counts'][$modelType]) ? $_SESSION['counts'][$modelType]++ : ($_SESSION['counts'][$modelType] = 1);
                             if ($lookupFlag) {
                                 isset($_SESSION['overwriten'][$modelType]) ? $_SESSION['overwriten'][$modelType]++ : ($_SESSION['overwriten'][$modelType] = 1);
                             } else {
                                 isset($_SESSION['overwriten'][$modelType]) ?: ($_SESSION['overwriten'][$modelType] = 0);
                             }
                         }
                     } else {
                         // Put the failed lead into the failed import CSV
                         //AuxLib::debugLogR ('failed to import '.get_class ($model));
                         //AuxLib::debugLogR ($model->getErrors ());
                         $failedImport = fopen($this->safePath('failedImport.csv'), 'a+');
                         $lastFailed = $_SESSION['lastFailed'];
                         if ($lastFailed != $modelType) {
                             $tempMeta = $metaData;
                             $tempMeta[] = $modelType;
                             fputcsv($failedImport, $tempMeta);
                         }
                         $attr = $model->attributes;
                         $tempAttributes = X2Model::model($modelType)->attributes;
                         $attr = array_merge($tempAttributes, $attr);
                         $attr[] = $modelType;
                         fputcsv($failedImport, $attr);
                         $_SESSION['lastFailed'] = $modelType;
                         isset($_SESSION['failed']) ? $_SESSION['failed']++ : ($_SESSION['failed'] = 1);
                     }
                 }
             } else {
                 // "0" at the beginning means we reached the end of the file
                 // and don't need to do another set.
                 echo json_encode(array(0, json_encode($_SESSION['counts']), json_encode($_SESSION['overwriten']), json_encode($_SESSION['failed']), json_encode($_SESSION['overwriteFailure'])));
                 return;
             }
         }
         // Update the file offset pointer in the session.
         $_SESSION['offset'] = ftell($fp);
         echo json_encode(array(1, json_encode($_SESSION['counts']), json_encode($_SESSION['overwriten']), json_encode($_SESSION['failed']), json_encode($_SESSION['overwriteFailure'])));
     }
 }
Пример #4
0
require_once "util/Imports.php";
require_once "util/ConexaoBD.php";
require_once 'util/Proxy.php';
Proxy::reset();
//DOMINIOS
//include 'model/dominio/TipoPerfil.php';
//MODEL
require_once "model/fachada/Fachada.php";
//Registra as Pages
Imports::page("HomePage");
Imports::page("SobrePage");
Imports::page("CadastrarPessoaPage");
Imports::page("CadastrarEmpreendimentoPage");
Imports::page("FaleConoscoPage");
Imports::page("ProgramacaoPage");
Imports::page("AdminPage");
Imports::page("ListagemPessoasPage");
Imports::page("ListagemEmpreendimentoPage");
Imports::page("ListagemMensagemPage");
Imports::page("DetalharMensagemPage");
Imports::page("DetalharPessoaPage");
Imports::page("DetalharEmpreendimentoPage");
Imports::page("FeiraPage");
Imports::page("CursoPage");
Imports::page("EmpreendimentosSegmentosPage");
//Registra as Actions
Imports::action("CadastrarPessoaAction");
Imports::action("CadastrarEmpreendimentoAction");
Imports::action("FaleConoscoAction");
Imports::action("RemoverMensagemAction");
Пример #5
0
 /**
  * Helper function to return the next importId
  * @return int Next import ID
  */
 private function getNextImportId()
 {
     $criteria = new CDbCriteria();
     $criteria->order = "importId DESC";
     $criteria->limit = 1;
     $import = Imports::model()->find($criteria);
     // Figure out which import this is so we can set up the Imports models
     // for this import.
     if (isset($import)) {
         $importId = $import->importId + 1;
     } else {
         $importId = 1;
     }
     return $importId;
 }
Пример #6
0
 public function apply()
 {
     if ($files = $this->getKitFiles()) {
         foreach ($files as $file => $path) {
             $import = new Imports($path);
             // Make a backup of the file.
             $this->writeFile($import->getSource(), $file, 'source');
             // Now store the compiled file
             $this->writeFile($import->apply(), $file, 'source');
             foreach ($import->getImports() as $key => $value) {
                 $this->imports[$key] = $value;
             }
         }
     }
     $files = array_diff_key($files, $this->imports);
     foreach ($files as $file => $path) {
         $variables = new Variables($path, TRUE);
         $variables->extract();
         $result = $variables->apply();
         $file = preg_replace('/\\.kit$/', '.html', $file);
         $path = $this->writeFile($result, $file);
         $this->exports[$file] = $path;
     }
     return $result;
 }
Пример #7
0
<?php

require_once "util/Constants.php";
require_once "util/Messages.php";
require_once "util/SessionManager.php";
require_once "util/ACL.php";
require_once "util/Page.php";
require_once "util/Form.php";
require_once "util/Entidade.php";
require_once "util/Action.php";
require_once "util/Forward.php";
require_once "util/Imports.php";
require_once "util/ConexaoBD.php";
require_once 'util/Proxy.php';
Proxy::reset();
//DOMINIOS
include 'model/dominio/TipoPerfil.php';
//MODEL
require_once "model/fachada/Fachada.php";
//Registra as Pages
Imports::page("HomePage");
Imports::page("CadastroTestePage");
//Registra as Actions
//Imports::action("AtualizarCursoAction");
Пример #8
0
 static function __import($scope)
 {
     Imports::$into = $scope;
 }
Пример #9
0
Imports::page("ChatPage");
Imports::page("HomePage");
Imports::page("ManterClientePage");
Imports::page("ManterProdutoPage");
Imports::page("ManterReservaPage");
Imports::page("ReservarProdutoPage");
Imports::page("DetalharReservaPage");
Imports::page("ListarReservaPage");
Imports::page("ProdutoPage");
Imports::page("ListagemProdutosPage");
Imports::page("PoliticasAtendimentoPage");
Imports::page("ClickVestPage");
Imports::page("RaioAtuacaoPage");
Imports::page("HistoricoReservaPage");
Imports::page("ServicoPage");
Imports::page("FormChatPage");
//Registra as Actions
Imports::action("CadastroUsuarioAction");
Imports::action("CadastrarProdutoAction");
Imports::action("LoginAction");
Imports::action("LogoutAction");
Imports::action("ChatAction");
Imports::action("RemoverClienteAction");
Imports::action("RemoverProdutoAction");
Imports::action("ReservarProdutoAction");
Imports::action("FecharReservasAction");
Imports::action("RemoverProdutoCarrinhoAction");
Imports::action("AtualizarPerfilAction");
Imports::action("AtualizarUsuarioAction");
Imports::action("AtualizarProdutoAction");