/**
  * Implementation for 'GET' method for Rest API
  *
  * @param  mixed $repTabUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function get($repTabUid = null)
 {
     $result = array();
     try {
         $noArguments = true;
         $argumentList = func_get_args();
         foreach ($argumentList as $arg) {
             if (!is_null($arg)) {
                 $noArguments = false;
             }
         }
         if ($noArguments) {
             $criteria = new Criteria('workflow');
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_UID);
             $criteria->addSelectColumn(ReportTablePeer::PRO_UID);
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_NAME);
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_TYPE);
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_GRID);
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_CONNECTION);
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_CREATE_DATE);
             $criteria->addSelectColumn(ReportTablePeer::REP_TAB_STATUS);
             $dataset = AppEventPeer::doSelectRS($criteria);
             $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($dataset->next()) {
                 $result[] = $dataset->getRow();
             }
         } else {
             $record = ReportTablePeer::retrieveByPK($repTabUid);
             if ($record) {
                 $result = $record->toArray(BasePeer::TYPE_FIELDNAME);
             } else {
                 $paramValues = "";
                 foreach ($argumentList as $arg) {
                     $paramValues .= strlen($paramValues) ? ', ' : '';
                     if (!is_null($arg)) {
                         $paramValues .= "{$arg}";
                     } else {
                         $paramValues .= "NULL";
                     }
                 }
                 throw new RestException(417, "table ReportTable ({$paramValues})");
             }
         }
     } catch (RestException $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
     return $result;
 }
 function saveConsolidated($data)
 {
     $status = $data['con_status'];
     $sTasUid = $data['tas_uid'];
     $sDynUid = $data['dyn_uid'];
     $sProUid = $data['pro_uid'];
     $sRepTabUid = $data['rep_uid'];
     $tableName = $data['table_name'];
     $title = $data['title'];
     if ($sRepTabUid != '') {
         if (!$status) {
             $oCaseConsolidated = new CaseConsolidatedCore();
             $oCaseConsolidated = CaseConsolidatedCorePeer::retrieveByPK($sTasUid);
             if (!is_object($oCaseConsolidated) || get_class($oCaseConsolidated) != 'CaseConsolidatedCore') {
                 $oCaseConsolidated = new CaseConsolidatedCore();
                 $oCaseConsolidated->setTasUid($sTasUid);
                 $oCaseConsolidated->setConStatus('INACTIVE');
                 $oCaseConsolidated->save();
             } else {
                 $oCaseConsolidated->delete();
             }
             return 1;
         }
         $rptUid = null;
         $criteria = new Criteria();
         $criteria->addSelectColumn(ReportTablePeer::REP_TAB_UID);
         $criteria->add(ReportTablePeer::REP_TAB_UID, $sRepTabUid);
         $rsCriteria = ReportTablePeer::doSelectRS($criteria);
         if ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $rptUid = $row[0];
         }
         $rpts = new ReportTables();
         if ($rptUid != null) {
             $rpts->deleteReportTable($rptUid);
         }
         $sClassName = $tableName;
         $sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
         @unlink($sPath . $sClassName . '.php');
         @unlink($sPath . $sClassName . 'Peer.php');
         @unlink($sPath . PATH_SEP . 'map' . PATH_SEP . $sClassName . 'MapBuilder.php');
         @unlink($sPath . PATH_SEP . 'om' . PATH_SEP . 'Base' . $sClassName . '.php');
         @unlink($sPath . PATH_SEP . 'om' . PATH_SEP . 'Base' . $sClassName . 'Peer.php');
         $sRepTabUid = '';
     }
     $_POST['form']['PRO_UID'] = $sProUid;
     $_POST['form']['REP_TAB_UID'] = $sRepTabUid;
     $_POST['form']['REP_TAB_NAME'] = $tableName;
     $_POST['form']['REP_TAB_TYPE'] = "NORMAL";
     $_POST['form']['REP_TAB_GRID'] = '';
     $_POST['form']['REP_TAB_CONNECTION'] = 'wf';
     $_POST['form']['REP_TAB_CREATE_DATE'] = date("Y-m-d H:i:s");
     $_POST['form']['REP_TAB_STATUS'] = 'ACTIVE';
     $_POST['form']['REP_TAB_TITLE'] = $title;
     $_POST['form']['FIELDS'] = array();
     G::LoadClass("reportTables");
     $oReportTable = new ReportTable();
     $sOldTableName = $_POST['form']['REP_TAB_NAME'];
     $sOldConnection = $_POST['form']['REP_TAB_CONNECTION'];
     $oReportTable->create($_POST['form']);
     $_POST['form']['REP_TAB_UID'] = $oReportTable->getRepTabUid();
     $oReportVar = new ReportVar();
     $oReportTables = new ReportTables();
     $oReportTables->deleteAllReportVars($_POST['form']['REP_TAB_UID']);
     $aFields = array();
     G::LoadClass("pmDynaform");
     $pmDyna = new pmDynaform(array());
     $pmDyna->fields["CURRENT_DYNAFORM"] = $sDynUid;
     $dataDyna = $pmDyna->getDynaform();
     $json = G::json_decode($dataDyna["DYN_CONTENT"]);
     $fieldsDyna = $json->items[0]->items;
     foreach ($fieldsDyna as $value) {
         foreach ($value as $val) {
             if (isset($val->type)) {
                 if ($val->type == 'text' || $val->type == 'textarea' || $val->type == 'dropdown' || $val->type == 'checkbox' || $val->type == 'datetime' || $val->type == 'yesno' || $val->type == 'date' || $val->type == 'hidden' || $val->type == 'currency' || $val->type == 'percentage' || $val->type == 'link') {
                     $_POST['form']['FIELDS'][] = $val->name . '-' . $val->type;
                 }
             }
         }
     }
     $aFieldsClases = array();
     $i = 1;
     $aFieldsClases[$i]['FLD_NAME'] = 'APP_UID';
     $aFieldsClases[$i]['FLD_NULL'] = 'off';
     $aFieldsClases[$i]['FLD_KEY'] = 'on';
     $aFieldsClases[$i]['FLD_AUTO_INCREMENT'] = 'off';
     $aFieldsClases[$i]['FLD_DESCRIPTION'] = '';
     $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR';
     $aFieldsClases[$i]['FLD_SIZE'] = 32;
     $i++;
     $aFieldsClases[$i]['FLD_NAME'] = 'APP_NUMBER';
     $aFieldsClases[$i]['FLD_NULL'] = 'off';
     $aFieldsClases[$i]['FLD_KEY'] = 'on';
     $aFieldsClases[$i]['FLD_AUTO_INCREMENT'] = 'off';
     $aFieldsClases[$i]['FLD_DESCRIPTION'] = '';
     $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR';
     $aFieldsClases[$i]['FLD_SIZE'] = 255;
     foreach ($_POST['form']['FIELDS'] as $sField) {
         $aField = explode('-', $sField);
         if ($aField[1] == 'title' || $aField[1] == 'submit') {
             continue;
         }
         $i++;
         $aFieldsClases[$i]['FLD_NAME'] = $aField[0];
         $aFieldsClases[$i]['FLD_NULL'] = 'off';
         $aFieldsClases[$i]['FLD_KEY'] = 'off';
         $aFieldsClases[$i]['FLD_AUTO_INCREMENT'] = 'off';
         $aFieldsClases[$i]['FLD_DESCRIPTION'] = '';
         switch ($aField[1]) {
             case 'currency':
             case 'percentage':
                 $sType = 'number';
                 $aFieldsClases[$i]['FLD_TYPE'] = 'FLOAT';
                 $aFieldsClases[$i]['FLD_SIZE'] = 255;
                 break;
             case 'text':
             case 'password':
             case 'dropdown':
             case 'yesno':
             case 'checkbox':
             case 'radiogroup':
             case 'hidden':
             case "link":
                 $sType = 'char';
                 $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR';
                 $aFieldsClases[$i]['FLD_SIZE'] = 255;
                 break;
             case 'textarea':
                 $sType = 'text';
                 $aFieldsClases[$i]['FLD_TYPE'] = 'TEXT';
                 $aFieldsClases[$i]['FLD_SIZE'] = '';
                 break;
             case 'date':
                 $sType = 'date';
                 $aFieldsClases[$i]['FLD_TYPE'] = 'DATE';
                 $aFieldsClases[$i]['FLD_SIZE'] = '';
                 break;
             default:
                 $sType = 'char';
                 $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR';
                 $aFieldsClases[$i]['FLD_SIZE'] = 255;
                 break;
         }
         $oReportVar->create(array('REP_TAB_UID' => $_POST['form']['REP_TAB_UID'], 'PRO_UID' => $_POST['form']['PRO_UID'], 'REP_VAR_NAME' => $aField[0], 'REP_VAR_TYPE' => $sType));
         $aFields[] = array('sFieldName' => $aField[0], 'sType' => $sType);
     }
     $_POST['form']['REP_TAB_TYPE'] = "NORMAL";
     $oReportTables->dropTable($sOldTableName, $sOldConnection);
     $oReportTables->createTable($_POST['form']['REP_TAB_NAME'], $_POST['form']['REP_TAB_CONNECTION'], $_POST['form']['REP_TAB_TYPE'], $aFields);
     $oReportTables->populateTable($_POST['form']['REP_TAB_NAME'], $_POST['form']['REP_TAB_CONNECTION'], $_POST['form']['REP_TAB_TYPE'], $aFields, $_POST['form']['PRO_UID'], '');
     $sRepTabUid = $_POST['form']['REP_TAB_UID'];
     $oCaseConsolidated = CaseConsolidatedCorePeer::retrieveByPK($sTasUid);
     if (!is_object($oCaseConsolidated) || get_class($oCaseConsolidated) != 'CaseConsolidatedCore') {
         $oCaseConsolidated = new CaseConsolidatedCore();
         $oCaseConsolidated->setTasUid($sTasUid);
     }
     $criteria = new Criteria();
     $criteria->addSelectColumn(CaseConsolidatedCorePeer::TAS_UID);
     $criteria->add(CaseConsolidatedCorePeer::TAS_UID, $sTasUid);
     $rsCriteria = CaseConsolidatedCorePeer::doSelectRS($criteria);
     if ($rsCriteria->next()) {
         $row = $rsCriteria->getRow();
         $oCaseConsolidated->delete();
         $oCaseConsolidated = CaseConsolidatedCorePeer::retrieveByPK($sTasUid);
     }
     if (!is_object($oCaseConsolidated) || get_class($oCaseConsolidated) != 'CaseConsolidatedCore') {
         $oCaseConsolidated = new CaseConsolidatedCore();
         $oCaseConsolidated->setTasUid($sTasUid);
     }
     $oCaseConsolidated->setConStatus('ACTIVE');
     $oCaseConsolidated->setDynUid($sDynUid);
     $oCaseConsolidated->setRepTabUid($sRepTabUid);
     $oCaseConsolidated->save();
     $sClassName = $tableName;
     $oAdditionalTables = new AdditionalTables();
     $oAdditionalTables->createPropelClasses($tableName, $sClassName, $aFieldsClases, $sTasUid);
 }
 /**
  * Function updateTables
  * This function updated the Report Tables
  *
  * @access public
  * @param string $sProcessUid
  * @param string $sApplicationUid
  * @param string $iApplicationNumber
  * @param string $aFields
  * @return void
  */
 public function updateTables($sProcessUid, $sApplicationUid, $iApplicationNumber, $aFields)
 {
     try {
         //get all Active Report Tables
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(ReportTablePeer::PRO_UID, $sProcessUid);
         $oCriteria->add(ReportTablePeer::REP_TAB_STATUS, 'ACTIVE');
         $oDataset = ReportTablePeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         $aVars = array();
         while ($aRow = $oDataset->getRow()) {
             $aRow['REP_TAB_NAME'] = $this->sPrefix . $aRow['REP_TAB_NAME'];
             $PropelDatabase = $this->chooseDB($aRow['REP_TAB_CONNECTION']);
             $con = Propel::getConnection($PropelDatabase);
             $stmt = $con->createStatement();
             switch (DB_ADAPTER) {
                 case 'mysql':
                     $aTableFields = $this->getTableVars($aRow['REP_TAB_UID'], true);
                     if ($aRow['REP_TAB_TYPE'] == 'NORMAL') {
                         $sqlExists = "SELECT * FROM `" . $aRow['REP_TAB_NAME'] . "` WHERE APP_UID = '" . $sApplicationUid . "'";
                         $rsExists = $stmt->executeQuery($sqlExists, ResultSet::FETCHMODE_ASSOC);
                         $rsExists->next();
                         $aRow2 = $rsExists->getRow();
                         if (is_array($aRow2)) {
                             $sQuery = 'UPDATE `' . $aRow['REP_TAB_NAME'] . '` SET ';
                             foreach ($aTableFields as $aField) {
                                 $sQuery .= '`' . $aField['sFieldName'] . '` = ';
                                 switch ($aField['sType']) {
                                     case 'number':
                                         $sQuery .= (isset($aFields[$aField['sFieldName']]) ? (double) str_replace(',', '', $aFields[$aField['sFieldName']]) : '0') . ',';
                                         break;
                                     case 'char':
                                     case 'text':
                                         if (!isset($aFields[$aField['sFieldName']])) {
                                             $aFields[$aField['sFieldName']] = '';
                                         }
                                         $sQuery .= "'" . (isset($aFields[$aField['sFieldName']]) ? mysql_real_escape_string($aFields[$aField['sFieldName']]) : '') . "',";
                                         break;
                                     case 'date':
                                         $mysqlDate = isset($aFields[$aField['sFieldName']]) ? $aFields[$aField['sFieldName']] : '';
                                         if ($mysqlDate != '') {
                                             $mysqlDate = str_replace('/', '-', $mysqlDate);
                                             $mysqlDate = date('Y-m-d', strtotime($mysqlDate));
                                         }
                                         $value = trim($mysqlDate) != '' ? "'" . $mysqlDate . "'" : 'NULL';
                                         $sQuery .= $value . ",";
                                         break;
                                 }
                             }
                             $sQuery = substr($sQuery, 0, -1);
                             $sQuery .= " WHERE APP_UID = '" . $sApplicationUid . "'";
                         } else {
                             $sQuery = 'INSERT INTO `' . $aRow['REP_TAB_NAME'] . '` (';
                             $sQuery .= '`APP_UID`,`APP_NUMBER`';
                             foreach ($aTableFields as $aField) {
                                 $sQuery .= ',`' . $aField['sFieldName'] . '`';
                             }
                             $sQuery .= ") VALUES ('" . $sApplicationUid . "'," . (int) $iApplicationNumber;
                             foreach ($aTableFields as $aField) {
                                 switch ($aField['sType']) {
                                     case 'number':
                                         $sQuery .= ',' . (isset($aFields[$aField['sFieldName']]) ? (double) str_replace(',', '', $aFields[$aField['sFieldName']]) : '0');
                                         break;
                                     case 'char':
                                     case 'text':
                                         if (!isset($aFields[$aField['sFieldName']])) {
                                             $aFields[$aField['sFieldName']] = '';
                                         }
                                         $sQuery .= ",'" . (isset($aFields[$aField['sFieldName']]) ? mysql_real_escape_string($aFields[$aField['sFieldName']]) : '') . "'";
                                         break;
                                     case 'date':
                                         $mysqlDate = isset($aFields[$aField['sFieldName']]) ? $aFields[$aField['sFieldName']] : '';
                                         if ($mysqlDate != '') {
                                             $mysqlDate = str_replace('/', '-', $mysqlDate);
                                             $mysqlDate = date('Y-m-d', strtotime($mysqlDate));
                                         }
                                         $value = trim($mysqlDate) != '' ? "'" . $mysqlDate . "'" : 'NULL';
                                         $sQuery .= "," . $value;
                                         break;
                                 }
                             }
                             $sQuery .= ')';
                         }
                         $rs = $stmt->executeQuery($sQuery);
                     } else {
                         //remove old rows from database
                         $sqlDelete = 'DELETE FROM `' . $aRow['REP_TAB_NAME'] . "` WHERE APP_UID = '" . $sApplicationUid . "'";
                         $rsDelete = $stmt->executeQuery($sqlDelete);
                         $aAux = explode('-', $aRow['REP_TAB_GRID']);
                         if (isset($aFields[$aAux[0]])) {
                             foreach ($aFields[$aAux[0]] as $iRow => $aGridRow) {
                                 $sQuery = 'INSERT INTO `' . $aRow['REP_TAB_NAME'] . '` (';
                                 $sQuery .= '`APP_UID`,`APP_NUMBER`,`ROW`';
                                 foreach ($aTableFields as $aField) {
                                     $sQuery .= ',`' . $aField['sFieldName'] . '`';
                                 }
                                 $sQuery .= ") VALUES ('" . $sApplicationUid . "'," . (int) $iApplicationNumber . ',' . $iRow;
                                 foreach ($aTableFields as $aField) {
                                     switch ($aField['sType']) {
                                         case 'number':
                                             $sQuery .= ',' . (isset($aGridRow[$aField['sFieldName']]) ? (double) str_replace(',', '', $aGridRow[$aField['sFieldName']]) : '0');
                                             break;
                                         case 'char':
                                         case 'text':
                                             if (!isset($aGridRow[$aField['sFieldName']])) {
                                                 $aGridRow[$aField['sFieldName']] = '';
                                             }
                                             $sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? mysql_real_escape_string($aGridRow[$aField['sFieldName']]) : '') . "'";
                                             break;
                                         case 'date':
                                             $sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? $aGridRow[$aField['sFieldName']] : '') . "'";
                                             break;
                                     }
                                 }
                                 $sQuery .= ')';
                                 $rs = $stmt->executeQuery($sQuery);
                             }
                         }
                     }
                     break;
                     /**
                      * For SQLServer code
                      */
                 /**
                  * For SQLServer code
                  */
                 case 'mssql':
                     $aTableFields = $this->getTableVars($aRow['REP_TAB_UID'], true);
                     if ($aRow['REP_TAB_TYPE'] == 'NORMAL') {
                         $oDataset2 = mssql_query("SELECT * FROM [" . $aRow['REP_TAB_NAME'] . "] WHERE APP_UID = '" . $sApplicationUid . "'");
                         if ($aRow2 = mssql_fetch_row($oDataset2)) {
                             $sQuery = 'UPDATE [' . $aRow['REP_TAB_NAME'] . '] SET ';
                             foreach ($aTableFields as $aField) {
                                 $sQuery .= '[' . $aField['sFieldName'] . '] = ';
                                 switch ($aField['sType']) {
                                     case 'number':
                                         $sQuery .= (isset($aFields[$aField['sFieldName']]) ? (double) str_replace(',', '', $aFields[$aField['sFieldName']]) : '0') . ',';
                                         break;
                                     case 'char':
                                     case 'text':
                                         if (!isset($aFields[$aField['sFieldName']])) {
                                             $aFields[$aField['sFieldName']] = '';
                                         }
                                         $sQuery .= "'" . (isset($aFields[$aField['sFieldName']]) ? mysql_real_escape_string($aFields[$aField['sFieldName']]) : '') . "',";
                                         break;
                                     case 'date':
                                         $sQuery .= "'" . (isset($aFields[$aField['sFieldName']]) ? $aFields[$aField['sFieldName']] : '') . "',";
                                         break;
                                 }
                             }
                             $sQuery = substr($sQuery, 0, -1);
                             $sQuery .= " WHERE APP_UID = '" . $sApplicationUid . "'";
                         } else {
                             $sQuery = 'INSERT INTO [' . $aRow['REP_TAB_NAME'] . '] (';
                             $sQuery .= '[APP_UID],[APP_NUMBER]';
                             foreach ($aTableFields as $aField) {
                                 $sQuery .= ',[' . $aField['sFieldName'] . ']';
                             }
                             $sQuery .= ") VALUES ('" . $sApplicationUid . "'," . (int) $iApplicationNumber;
                             foreach ($aTableFields as $aField) {
                                 switch ($aField['sType']) {
                                     case 'number':
                                         $sQuery .= ',' . (isset($aFields[$aField['sFieldName']]) ? (double) str_replace(',', '', $aFields[$aField['sFieldName']]) : '0');
                                         break;
                                     case 'char':
                                     case 'text':
                                         if (!isset($aFields[$aField['sFieldName']])) {
                                             $aFields[$aField['sFieldName']] = '';
                                         }
                                         $sQuery .= ",'" . (isset($aFields[$aField['sFieldName']]) ? mysql_real_escape_string($aFields[$aField['sFieldName']]) : '') . "'";
                                         break;
                                     case 'date':
                                         $sQuery .= ",'" . (isset($aFields[$aField['sFieldName']]) ? $aFields[$aField['sFieldName']] : '') . "'";
                                         break;
                                 }
                             }
                             $sQuery .= ')';
                         }
                         $rs = $stmt->executeQuery($sQuery);
                     } else {
                         mysql_query('DELETE FROM [' . $aRow['REP_TAB_NAME'] . "] WHERE APP_UID = '" . $sApplicationUid . "'");
                         $aAux = explode('-', $aRow['REP_TAB_GRID']);
                         if (isset($aFields[$aAux[0]])) {
                             foreach ($aFields[$aAux[0]] as $iRow => $aGridRow) {
                                 $sQuery = 'INSERT INTO [' . $aRow['REP_TAB_NAME'] . '] (';
                                 $sQuery .= '[APP_UID],[APP_NUMBER],[ROW]';
                                 foreach ($aTableFields as $aField) {
                                     $sQuery .= ',[' . $aField['sFieldName'] . ']';
                                 }
                                 $sQuery .= ") VALUES ('" . $sApplicationUid . "'," . (int) $iApplicationNumber . ',' . $iRow;
                                 foreach ($aTableFields as $aField) {
                                     switch ($aField['sType']) {
                                         case 'number':
                                             $sQuery .= ',' . (isset($aGridRow[$aField['sFieldName']]) ? (double) str_replace(',', '', $aGridRow[$aField['sFieldName']]) : '0');
                                             break;
                                         case 'char':
                                         case 'text':
                                             if (!isset($aGridRow[$aField['sFieldName']])) {
                                                 $aGridRow[$aField['sFieldName']] = '';
                                             }
                                             $sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? mysql_real_escape_string($aGridRow[$aField['sFieldName']]) : '') . "'";
                                             break;
                                         case 'date':
                                             $sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? $aGridRow[$aField['sFieldName']] : '') . "'";
                                             break;
                                     }
                                 }
                                 $sQuery .= ')';
                                 $rs = $stmt->executeQuery($sQuery);
                             }
                         }
                     }
                     break;
             }
             $oDataset->next();
         }
     } catch (Exception $oError) {
         throw $oError;
     }
 }
    /**

     * Create Report Tables from an array of data

     *

     * @param array $aReportTables

     * @param array $aReportTablesVars

     * @return void

     */

    public function createReportTables ($aReportTables, $aReportTablesVars)

    {

        $this->createReportTablesVars( $aReportTablesVars );

        $oReportTables = new ReportTables();

        foreach ($aReportTables as $sKey => $aRow) {

            $bExists = true;

            $sTable = $aRow['REP_TAB_NAME'];

            $iCounter = 1;

            while ($bExists) {

                $oCriteria = new Criteria( 'workflow' );

                $oCriteria->add( ReportTablePeer::REP_TAB_NAME, $sTable );

                $oDataset = ReportTablePeer::doSelectRS( $oCriteria );

                $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );

                $oDataset->next();

                $bExists = ($aRow2 = $oDataset->getRow());

                if ($bExists) {

                    $sTable = $aRow['REP_TAB_NAME'] . '_' . $iCounter;

                    $iCounter ++;

                } else {

                    $aRow['REP_TAB_NAME'] = $sTable;

                }

            }

            $aFields = $oReportTables->getTableVars( $aRow['REP_TAB_UID'], true );

            $oReportTables->createTable( $aRow['REP_TAB_NAME'], $aRow['REP_TAB_CONNECTION'], $aRow['REP_TAB_TYPE'], $aFields );

            $oReportTables->populateTable( $aRow['REP_TAB_NAME'], $aRow['REP_TAB_CONNECTION'], $aRow['REP_TAB_TYPE'], $aFields, $aRow['PRO_UID'], $aRow['REP_TAB_GRID'] );

            $aReportTables[$sKey]['REP_TAB_NAME'] = $aRow['REP_TAB_NAME'];

            $oRep = new ReportTable();

            if ($oRep->reportTableExists( $aRow['REP_TAB_UID'] )) {

                $oRep->remove( $aRow['REP_TAB_UID'] );

            }

            $oRep->create( $aRow );

        }

    }
Exemple #5
0
 function reportTableExists($RepTabUid)
 {
     $con = Propel::getConnection(ReportTablePeer::DATABASE_NAME);
     try {
         $oRepTabUid = ReportTablePeer::retrieveByPk($RepTabUid);
         if (is_object($oRepTabUid) && get_class($oRepTabUid) == 'ReportTable') {
             return true;
         } else {
             return false;
         }
     } catch (Exception $oError) {
         throw $oError;
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      Connection $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(ReportTablePeer::REP_TAB_UID, $pks, Criteria::IN);
         $objs = ReportTablePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
    public function con_save_properties($sTasUid, $sDynUid, $sStatus, $sProUid, $sRepTabUid, $tableName, $title, $swOverwrite)
    {
        G::LoadClass("reportTables");

        if ($sStatus == "1" && $sDynUid != "") {
            //Verified as not to duplicate the name of the table

            switch ($swOverwrite) {
                case 1:
                    //Delete report table
                    $criteria = new Criteria();

                    $criteria->addSelectColumn(ReportTablePeer::REP_TAB_UID);
                    $criteria->add(ReportTablePeer::REP_TAB_NAME, $tableName);

                    $rsCriteria = ReportTablePeer::doSelectRS($criteria);

                    $rptUid = null;

                    if ($rsCriteria->next()) {
                        $row = $rsCriteria->getRow();

                        $rptUid = $row[0];
                    }

                    $rpts = new ReportTables();

                    if ($rptUid != null) {
                        $rpts->deleteReportTable($rptUid);
                    }

                    $sRepTabUid = "";
                    break;
                case 2:
                    //Delete table
                    $rpts = new ReportTables();
                    $rpts->dropTable($tableName, "wf");

                    $sRepTabUid = "";
                    break;
            }

            $criteria = new Criteria();
            $criteria->addSelectColumn(ReportTablePeer::REP_TAB_UID);
            //$criteria->add(ReportTablePeer::PRO_UID, $sProUid);
            $criteria->add(ReportTablePeer::REP_TAB_NAME, $tableName);

            $result = ReportTablePeer::doSelectRS($criteria);
            $result->setFetchmode(ResultSet::FETCHMODE_ASSOC);

            if ($result->next()) {
                $dataRes = $result->getRow();

                if ($dataRes["REP_TAB_UID"] != $sRepTabUid) {
                    return 1;
                }
            } else {
                //check if table $tableName exists
                $con = Propel::getConnection("workflow");
                $stmt = $con->createStatement();

                $sql="SHOW TABLES";
                $rs1 = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM);
                $rs1->next();
                while ( is_array($row = $rs1->getRow() )) {
                    if ( $row[0] == $tableName ) {
                        return 2;
                    }
                    $rs1->next();
                }
            }

            $_POST['form']['PRO_UID'] = $sProUid;
            $_POST['form']['REP_TAB_UID']  = $sRepTabUid;
            $_POST['form']['REP_TAB_NAME'] = $tableName;
            $_POST['form']['REP_TAB_TYPE'] = "GRID";
            $_POST['form']['REP_TAB_GRID'] = $sProUid . "-" . $sDynUid;
            $_POST['form']['REP_TAB_CONNECTION'] = 'wf';
            $_POST['form']['REP_TAB_CREATE_DATE'] = date("Y-m-d H:i:s");
            $_POST['form']['REP_TAB_STATUS'] = 'ACTIVE';
            $_POST['form']['REP_TAB_TITLE'] = $title;

            $_POST['form']['FIELDS'] = array();

            G::LoadClass("reportTables");

            $oReportTable = new ReportTable();
            //if (!isset($_POST['form']['REP_TAB_CONNECTION'])) {
            //  $_POST['form']['REP_TAB_CONNECTION'] = 'report';
            //}
            if ($_POST['form']['REP_TAB_UID'] != "") {
                $aReportTable   = $oReportTable->load($_POST['form']['REP_TAB_UID']);
                $sOldTableName  = $aReportTable['REP_TAB_NAME'];
                $sOldConnection = $aReportTable['REP_TAB_CONNECTION'];
            } else {
                $sOldTableName  = $_POST['form']['REP_TAB_NAME'];
                $sOldConnection = $_POST['form']['REP_TAB_CONNECTION'];
                $_POST['form']['REP_TAB_TYPE'] = 'NORMAL';
                $oReportTable->create($_POST['form']);
                $_POST['form']['REP_TAB_UID'] = $oReportTable->getRepTabUid();
            }

            $_POST['form']['REP_TAB_TYPE'] = 'NORMAL';
            $oReportTable->update($_POST['form']);

            $_POST['form']['REP_TAB_TYPE'] = 'GRID';

            $oReportVar = new ReportVar();
            $oReportTables = new ReportTables();
            $oReportTables->deleteAllReportVars($_POST['form']['REP_TAB_UID']);

            $aFields = array();

            if ($_POST['form']['REP_TAB_TYPE'] == 'GRID') {
                $aAux = explode('-', $_POST['form']['REP_TAB_GRID']);
                global $G_FORM;

                G::LoadClass("formBatchRouting");
                $G_FORM = new FormBatchRouting($_POST["form"]["PRO_UID"] . PATH_SEP . $aAux[1], PATH_DYNAFORM, SYS_LANG, false);
                $aAux = $G_FORM->getVars(false);

                foreach ($aAux as $aField) {
                    $_POST['form']['FIELDS'][] = $aField['sName'] . '-' . $aField['sType'];
                }
            }

            $aFieldsClases = array();
            $i = 1;
            $aFieldsClases[$i]['FLD_NAME'] = 'APP_UID';
            $aFieldsClases[$i]['FLD_NULL'] = 'off';
            $aFieldsClases[$i]['FLD_KEY'] = 'on';
            $aFieldsClases[$i]['FLD_AUTO_INCREMENT'] = 'off';
            $aFieldsClases[$i]['FLD_DESCRIPTION'] = '';
            $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR' ;
            $aFieldsClases[$i]['FLD_SIZE'] = 32;
            $i++;
            $aFieldsClases[$i]['FLD_NAME'] = 'APP_NUMBER';
            $aFieldsClases[$i]['FLD_NULL'] = 'off';
            $aFieldsClases[$i]['FLD_KEY'] = 'on';
            $aFieldsClases[$i]['FLD_AUTO_INCREMENT'] = 'off';
            $aFieldsClases[$i]['FLD_DESCRIPTION'] = '';
            $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR' ;
            $aFieldsClases[$i]['FLD_SIZE'] = 255;

            foreach ($_POST['form']['FIELDS'] as $sField) {
                $aField = explode('-', $sField);
                $i++;
                $aFieldsClases[$i]['FLD_NAME'] = $aField[0];
                $aFieldsClases[$i]['FLD_NULL'] = 'off';
                $aFieldsClases[$i]['FLD_KEY'] = 'off';
                $aFieldsClases[$i]['FLD_AUTO_INCREMENT'] = 'off';
                $aFieldsClases[$i]['FLD_DESCRIPTION'] = '';

                switch ($aField[1]) {
                    case 'currency':
                    case 'percentage':
                        $sType = 'number';
                        $aFieldsClases[$i]['FLD_TYPE'] = 'FLOAT' ;
                        $aFieldsClases[$i]['FLD_SIZE'] = 255;
                        break;
                    case 'text':
                    case 'password':
                    case 'dropdown':
                    case 'yesno':
                    case 'checkbox':
                    case 'radiogroup':
                    case 'hidden':
                    case "link":
                        $sType = 'char';
                        $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR' ;
                        $aFieldsClases[$i]['FLD_SIZE'] = 255;
                        break;
                    case 'textarea':
                        $sType = 'text';
                        $aFieldsClases[$i]['FLD_TYPE'] = 'TEXT' ;
                        $aFieldsClases[$i]['FLD_SIZE'] = '';
                        break;
                    case 'date':
                        $sType = 'date';
                        $aFieldsClases[$i]['FLD_TYPE'] = 'DATE' ;
                        $aFieldsClases[$i]['FLD_SIZE'] = '';
                        break;
                    default:
                        $sType = 'char';
                        $aFieldsClases[$i]['FLD_TYPE'] = 'VARCHAR' ;
                        $aFieldsClases[$i]['FLD_SIZE'] = 255;
                        break;
                }

                $oReportVar->create(array('REP_TAB_UID'  => $_POST['form']['REP_TAB_UID'],
                                          'PRO_UID'      => $_POST['form']['PRO_UID'],
                                          'REP_VAR_NAME' => $aField[0],
                                          'REP_VAR_TYPE' => $sType));
                $aFields[] = array('sFieldName' => $aField[0], 'sType' => $sType);
            }

            $_POST['form']['REP_TAB_TYPE'] = "NORMAL";
            $oReportTables->dropTable($sOldTableName, $sOldConnection);
            $oReportTables->createTable($_POST['form']['REP_TAB_NAME'], $_POST['form']['REP_TAB_CONNECTION'], $_POST['form']['REP_TAB_TYPE'], $aFields);
            $oReportTables->populateTable($_POST['form']['REP_TAB_NAME'], $_POST['form']['REP_TAB_CONNECTION'], $_POST['form']['REP_TAB_TYPE'], $aFields, $_POST['form']['PRO_UID'], '');

            $sRepTabUid = $_POST['form']['REP_TAB_UID'];

            //clases
        } else {
            $oReportTables = new ReportTables();
            if ($sRepTabUid != "") {
                $oReportTables->deleteReportTable($sRepTabUid);
            }
            $sRepTabUid = "";
        }

        $oCaseConsolidated = CaseConsolidatedPeer::retrieveByPK($sTasUid);

        if (!(is_object($oCaseConsolidated)) || get_class($oCaseConsolidated) != 'CaseConsolidated') {
            $oCaseConsolidated = new CaseConsolidated();
            $oCaseConsolidated->setTasUid($sTasUid);
        }

        if ($sStatus == '1') {
            $oCaseConsolidated->setConStatus('ACTIVE');
        } else {
            $oCaseConsolidated->setConStatus('INACTIVE');
        }

        $oCaseConsolidated->setDynUid($sDynUid);
        $oCaseConsolidated->setRepTabUid($sRepTabUid);
        $oCaseConsolidated->save();

        $sClassName = $tableName;//'__' . $sTasUid;

        if ($sStatus == '1') {
            //$oAdditionalTables->createPropelClasses($sTableName, $sClassName, $aFields, $sAddTabUid)
            //require_once 'classes/model/AdditionalTables.php';
            //$oAdditionalTables = new AdditionalTables();
            $oAdditionalTables = new AdditionalTables();//AdditionalTablesConsolidated

            $oAdditionalTables->createPropelClasses($tableName, $sClassName, $aFieldsClases, $sTasUid);
        } else {
            $sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
            @unlink($sPath . $sClassName . '.php');
            @unlink($sPath . $sClassName . 'Peer.php');
            @unlink($sPath . PATH_SEP . 'map' . PATH_SEP . $sClassName . 'MapBuilder.php');
            @unlink($sPath . PATH_SEP . 'om' . PATH_SEP . 'Base' . $sClassName . '.php');
            @unlink($sPath . PATH_SEP . 'om' . PATH_SEP . 'Base' . $sClassName . 'Peer.php');
        }

        return ($sRepTabUid);
    }
 public function getExtReportTables($start, $limit, $sProcessUID = '')
 {
     $sDelimiter = DBAdapter::getStringDelimiter();
     $oCriteria = new Criteria('workflow');
     $oCriteria->addSelectColumn(ReportTablePeer::REP_TAB_UID);
     $oCriteria->addSelectColumn(ReportTablePeer::PRO_UID);
     // $oCriteria->addAsColumn ( 'REP_TAB_TITLE', 'C.CON_VALUE' );
     $oCriteria->addAsColumn('REP_TAB_TITLE', "CASE WHEN C.CON_VALUE IS NULL THEN (SELECT DISTINCT MAX(A.CON_VALUE) FROM CONTENT A WHERE A.CON_ID = REPORT_TABLE.REP_TAB_UID ) ELSE C.CON_VALUE  END ");
     $oCriteria->addAlias('C', 'CONTENT');
     $aConditions = array();
     $aConditions[] = array(ReportTablePeer::REP_TAB_UID, 'C.CON_ID');
     $aConditions[] = array('C.CON_CATEGORY', $sDelimiter . 'REP_TAB_TITLE' . $sDelimiter);
     $aConditions[] = array('C.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter);
     $oCriteria->addJoinMC($aConditions, Criteria::LEFT_JOIN);
     $oCriteria->add(ReportTablePeer::PRO_UID, $sProcessUID);
     $this->tmpCriteria = clone $oCriteria;
     if ($start != '') {
         $oCriteria->setOffset($start);
     }
     if ($limit != '') {
         $oCriteria->setLimit($limit);
     }
     $oDataset = ReportTablePeer::doSelectRS($oCriteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $oDataset->next();
     while ($aRow = $oDataset->getRow()) {
         $aReportTable[] = array('REP_TAB_UID' => $aRow['REP_TAB_UID'], 'REP_TAB_TITLE' => $aRow['REP_TAB_TITLE']);
         $oDataset->next();
     }
     return $aReportTable;
 }
Exemple #9
0
 public function deleteProcess($sProcessUID, $flagRemoveCases = true)
 {
     try {
         //G::LoadClass('case');
         //G::LoadClass('reportTables');
         //Instance all classes necesaries
         $oProcess = new \Process();
         $oDynaform = new \Dynaform();
         $oInputDocument = new \InputDocument();
         $oOutputDocument = new \OutputDocument();
         $oTrigger = new \Triggers();
         $oRoute = new \Route();
         $oGateway = new \Gateway();
         $oEvent = new \Event();
         $oSwimlaneElement = new \SwimlanesElements();
         $oConfiguration = new \Configuration();
         $oDbSource = new \DbSource();
         $oReportTable = new \ReportTables();
         $oCaseTracker = new \CaseTracker();
         $oCaseTrackerObject = new \CaseTrackerObject();
         //Update PROCESS_FILES_CHECKED
         $configuration = \ConfigurationPeer::retrieveByPK("PROCESS_FILES_CHECKED", "", "", "", "");
         if (!is_null($configuration)) {
             $arrayProjectUid = unserialize($configuration->getCfgValue());
             unset($arrayProjectUid[$sProcessUID]);
             $conf = new \Configuration();
             $result = $conf->update(array("CFG_UID" => "PROCESS_FILES_CHECKED", "OBJ_UID" => "", "CFG_VALUE" => serialize($arrayProjectUid), "PRO_UID" => "", "USR_UID" => "", "APP_UID" => ""));
         }
         //Delete the applications of process
         if ($flagRemoveCases) {
             $case = new \Cases();
             $criteria = new \Criteria("workflow");
             $criteria->addSelectColumn(\ApplicationPeer::APP_UID);
             $criteria->add(\ApplicationPeer::PRO_UID, $sProcessUID, \Criteria::EQUAL);
             $rsCriteria = \ApplicationPeer::doSelectRS($criteria);
             $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             while ($rsCriteria->next()) {
                 $row = $rsCriteria->getRow();
                 $result = $case->removeCase($row["APP_UID"]);
             }
         }
         //Delete the tasks of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\TaskPeer::PRO_UID, $sProcessUID);
         $oDataset = \TaskPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             //$this->deleteTask($aRow['TAS_UID']);
             $oTasks = new \Tasks();
             $oTasks->deleteTask($aRow['TAS_UID']);
             $oDataset->next();
         }
         //Delete the dynaforms of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\DynaformPeer::PRO_UID, $sProcessUID);
         $oDataset = \DynaformPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oDynaform->remove($aRow['DYN_UID']);
             $oDataset->next();
         }
         //Delete the input documents of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\InputDocumentPeer::PRO_UID, $sProcessUID);
         $oDataset = \InputDocumentPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oInputDocument->remove($aRow['INP_DOC_UID']);
             $oDataset->next();
         }
         //Delete the output documents of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\OutputDocumentPeer::PRO_UID, $sProcessUID);
         $oDataset = \OutputDocumentPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oOutputDocument->remove($aRow['OUT_DOC_UID']);
             $oDataset->next();
         }
         //Delete the triggers of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\TriggersPeer::PRO_UID, $sProcessUID);
         $oDataset = \TriggersPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oTrigger->remove($aRow['TRI_UID']);
             $oDataset->next();
         }
         //Delete the routes of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\RoutePeer::PRO_UID, $sProcessUID);
         $oDataset = \RoutePeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oRoute->remove($aRow['ROU_UID']);
             $oDataset->next();
         }
         //Delete the gateways of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\GatewayPeer::PRO_UID, $sProcessUID);
         $oDataset = \GatewayPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oGateway->remove($aRow['GAT_UID']);
             $oDataset->next();
         }
         //Delete the Event of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\EventPeer::PRO_UID, $sProcessUID);
         $oDataset = \EventPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oEvent->remove($aRow['EVN_UID']);
             $oDataset->next();
         }
         //Delete the swimlanes elements of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\SwimlanesElementsPeer::PRO_UID, $sProcessUID);
         $oDataset = \SwimlanesElementsPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oSwimlaneElement->remove($aRow['SWI_UID']);
             $oDataset->next();
         }
         //Delete the configurations of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\ConfigurationPeer::PRO_UID, $sProcessUID);
         $oDataset = \ConfigurationPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oConfiguration->remove($aRow['CFG_UID'], $aRow['OBJ_UID'], $aRow['PRO_UID'], $aRow['USR_UID'], $aRow['APP_UID']);
             $oDataset->next();
         }
         //Delete the DB sources of process
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\DbSourcePeer::PRO_UID, $sProcessUID);
         $oDataset = \DbSourcePeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             /**
              * note added by gustavo cruz gustavo-at-colosa-dot-com 27-01-2010
              * in order to solve the bug 0004389, we use the validation function Exists
              * inside the remove function in order to verify if the DbSource record
              * exists in the Database, however there is a strange behavior within the
              * propel engine, when the first record is erased somehow the "_deleted"
              * attribute of the next row is set to true, so when propel tries to erase
              * it, obviously it can't and trows an error. With the "Exist" function
              * we ensure that if there is the record in the database, the _delete attribute must be false.
              *
              * note added by gustavo cruz gustavo-at-colosa-dot-com 28-01-2010
              * I have just identified the source of the issue, when is created a $oDbSource DbSource object
              * it's used whenever a record is erased or removed in the db, however the problem
              * it's that the same object is used every time, and the delete method invoked
              * sets the _deleted attribute to true when its called, of course as we use
              * the same object, the first time works fine but trowns an error with the
              * next record, cos it's the same object and the delete method checks if the _deleted
              * attribute it's true or false, the attrib _deleted is setted to true the
              * first time and later is never changed, the issue seems to be part of
              * every remove function in the model classes, not only DbSource
              * i recommend that a more general solution must be achieved to resolve
              * this issue in every model class, to prevent future problems.
              */
             $oDbSource->remove($aRow['DBS_UID'], $sProcessUID);
             $oDataset->next();
         }
         //Delete the supervisors
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\ProcessUserPeer::PRO_UID, $sProcessUID);
         \ProcessUserPeer::doDelete($oCriteria);
         //Delete the object permissions
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\ObjectPermissionPeer::PRO_UID, $sProcessUID);
         \ObjectPermissionPeer::doDelete($oCriteria);
         //Delete the step supervisors
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\StepSupervisorPeer::PRO_UID, $sProcessUID);
         \StepSupervisorPeer::doDelete($oCriteria);
         //Delete the report tables
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\ReportTablePeer::PRO_UID, $sProcessUID);
         $oDataset = \ReportTablePeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         while ($aRow = $oDataset->getRow()) {
             $oReportTable->deleteReportTable($aRow['REP_TAB_UID']);
             $oDataset->next();
         }
         //Delete case tracker configuration
         $oCaseTracker->remove($sProcessUID);
         //Delete case tracker objects
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\CaseTrackerObjectPeer::PRO_UID, $sProcessUID);
         \ProcessUserPeer::doDelete($oCriteria);
         //Delete SubProcess
         $criteria = new \Criteria("workflow");
         $criteria->add(\SubProcessPeer::PRO_PARENT, $sProcessUID, \Criteria::EQUAL);
         $result = \SubProcessPeer::doDelete($criteria);
         //Delete WebEntries
         $webEntry = new \ProcessMaker\BusinessModel\WebEntry();
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\WebEntryPeer::WE_UID);
         $criteria->add(\WebEntryPeer::PRO_UID, $sProcessUID, \Criteria::EQUAL);
         $rsCriteria = \WebEntryPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $webEntry->delete($row["WE_UID"]);
         }
         //Delete WebEntry-Events
         $webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\WebEntryEventPeer::WEE_UID);
         $criteria->add(\WebEntryEventPeer::PRJ_UID, $sProcessUID, \Criteria::EQUAL);
         $rsCriteria = \WebEntryEventPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $webEntryEvent->delete($row["WEE_UID"]);
         }
         //Delete MessageTypes
         $messageType = new \ProcessMaker\BusinessModel\MessageType();
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\MessageTypePeer::MSGT_UID);
         $criteria->add(\MessageTypePeer::PRJ_UID, $sProcessUID, \Criteria::EQUAL);
         $rsCriteria = \MessageTypePeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $messageType->delete($row["MSGT_UID"]);
         }
         //Delete Message-Event-Relation
         $messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
         $messageEventRelation->deleteWhere(array(\MessageEventRelationPeer::PRJ_UID => $sProcessUID));
         //Delete Message-Event-Task-Relation
         $elementTaskRelation = new \ProcessMaker\BusinessModel\ElementTaskRelation();
         $elementTaskRelation->deleteWhere(array(\ElementTaskRelationPeer::PRJ_UID => $sProcessUID));
         //Delete Message-Event-Definition
         $messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_UID);
         $criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $sProcessUID, \Criteria::EQUAL);
         $rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $messageEventDefinition->delete($row["MSGED_UID"]);
         }
         //Delete Script-Task
         $scriptTask = new \ProcessMaker\BusinessModel\ScriptTask();
         $scriptTask->deleteWhere(array(\ScriptTaskPeer::PRJ_UID => array($sProcessUID, \Criteria::EQUAL)));
         //Delete Timer-Event
         $timerEvent = new \ProcessMaker\BusinessModel\TimerEvent();
         $timerEvent->deleteWhere(array(\TimerEventPeer::PRJ_UID => array($sProcessUID, \Criteria::EQUAL)));
         //Delete Email-Event
         $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_UID);
         $criteria->add(\EmailEventPeer::PRJ_UID, $sProcessUID, \Criteria::EQUAL);
         $rsCriteria = \EmailEventPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $emailEvent->delete($sProcessUID, $row["EMAIL_EVENT_UID"], false);
         }
         //Delete files Manager
         $filesManager = new \ProcessMaker\BusinessModel\FilesManager();
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\ProcessFilesPeer::PRF_UID);
         $criteria->add(\ProcessFilesPeer::PRO_UID, $sProcessUID, \Criteria::EQUAL);
         $rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $filesManager->deleteProcessFilesManager($sProcessUID, $row["PRF_UID"]);
         }
         //Delete the actions by email
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(\AbeConfigurationPeer::PRO_UID, $sProcessUID);
         \AbeConfigurationPeer::doDelete($oCriteria);
         //Delete the process
         try {
             $oProcess->remove($sProcessUID);
         } catch (\Exception $oError) {
             throw $oError;
         }
         return true;
     } catch (\Exception $oError) {
         throw $oError;
     }
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = ReportTablePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setRepTabUid($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setProUid($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setRepTabName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setRepTabType($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setRepTabGrid($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setRepTabConnection($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setRepTabCreateDate($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setRepTabStatus($arr[$keys[7]]);
     }
 }
Exemple #11
0
    /**
     * Delete Process
     *
     * @param string $processUid
     * @param bool   $checkCases
     *
     * return bool   Return true, if is succesfully
     *
     * @access public

    DEPRECATED
    public function deleteProcess($processUid, $checkCases = true)
    {
        if ($checkCases) {
            $process = new \Process();

            $arrayCases = $process->getCasesCountInAllProcesses($processUid);

            $sum = 0;

            if (isset($arrayCases[$processUid]) && count($arrayCases[$processUid]) > 0) {
                foreach ($arrayCases[$processUid] as $value) {
                    $sum = $sum + $value;
                }
            }

            if ($sum > 0) {
                throw (new \Exception("You can't delete the process, because it has $sum cases"));
            }
        }

        $processMap = new \processMap();

        return $processMap->deleteProcess($processUid);

    }*/

    public function deleteProcess($sProcessUID)
    {
        try {
            G::LoadClass('case');
            G::LoadClass('reportTables');
            //Instance all classes necesaries
            $oProcess = new Process();
            $oDynaform = new Dynaform();
            $oInputDocument = new InputDocument();
            $oOutputDocument = new OutputDocument();
            $oTrigger = new Triggers();
            $oRoute = new Route();
            $oGateway = new Gateway();
            $oEvent = new Event();
            $oSwimlaneElement = new SwimlanesElements();
            $oConfiguration = new Configuration();
            $oDbSource = new DbSource();
            $oReportTable = new ReportTables();
            $oCaseTracker = new CaseTracker();
            $oCaseTrackerObject = new CaseTrackerObject();
            //Delete the applications of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(ApplicationPeer::PRO_UID, $sProcessUID);
            $oDataset = ApplicationPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            $oCase = new Cases();
            while ($aRow = $oDataset->getRow()) {
                $oCase->removeCase($aRow['APP_UID']);
                $oDataset->next();
            }
            //Delete the tasks of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(TaskPeer::PRO_UID, $sProcessUID);
            $oDataset = TaskPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $this->deleteTask($aRow['TAS_UID']);
                $oDataset->next();
            }
            //Delete the dynaforms of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(DynaformPeer::PRO_UID, $sProcessUID);
            $oDataset = DynaformPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oDynaform->remove($aRow['DYN_UID']);
                $oDataset->next();
            }
            //Delete the input documents of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(InputDocumentPeer::PRO_UID, $sProcessUID);
            $oDataset = InputDocumentPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oInputDocument->remove($aRow['INP_DOC_UID']);
                $oDataset->next();
            }
            //Delete the output documents of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(OutputDocumentPeer::PRO_UID, $sProcessUID);
            $oDataset = OutputDocumentPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oOutputDocument->remove($aRow['OUT_DOC_UID']);
                $oDataset->next();
            }

            //Delete the triggers of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(TriggersPeer::PRO_UID, $sProcessUID);
            $oDataset = TriggersPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oTrigger->remove($aRow['TRI_UID']);
                $oDataset->next();
            }

            //Delete the routes of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(RoutePeer::PRO_UID, $sProcessUID);
            $oDataset = RoutePeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oRoute->remove($aRow['ROU_UID']);
                $oDataset->next();
            }

            //Delete the gateways of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(GatewayPeer::PRO_UID, $sProcessUID);
            $oDataset = GatewayPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oGateway->remove($aRow['GAT_UID']);
                $oDataset->next();
            }

            //Delete the Event of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(EventPeer::PRO_UID, $sProcessUID);
            $oDataset = EventPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oEvent->remove($aRow['EVN_UID']);
                $oDataset->next();
            }

            //Delete the swimlanes elements of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(SwimlanesElementsPeer::PRO_UID, $sProcessUID);
            $oDataset = SwimlanesElementsPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oSwimlaneElement->remove($aRow['SWI_UID']);
                $oDataset->next();
            }
            //Delete the configurations of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(ConfigurationPeer::PRO_UID, $sProcessUID);
            $oDataset = ConfigurationPeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oConfiguration->remove($aRow['CFG_UID'], $aRow['OBJ_UID'], $aRow['PRO_UID'], $aRow['USR_UID'], $aRow['APP_UID']);
                $oDataset->next();
            }
            //Delete the DB sources of process
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(DbSourcePeer::PRO_UID, $sProcessUID);
            $oDataset = DbSourcePeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {

                /**
                 * note added by gustavo cruz gustavo-at-colosa-dot-com 27-01-2010
                 * in order to solve the bug 0004389, we use the validation function Exists
                 * inside the remove function in order to verify if the DbSource record
                 * exists in the Database, however there is a strange behavior within the
                 * propel engine, when the first record is erased somehow the "_deleted"
                 * attribute of the next row is set to true, so when propel tries to erase
                 * it, obviously it can't and trows an error. With the "Exist" function
                 * we ensure that if there is the record in the database, the _delete attribute must be false.
                 *
                 * note added by gustavo cruz gustavo-at-colosa-dot-com 28-01-2010
                 * I have just identified the source of the issue, when is created a $oDbSource DbSource object
                 * it's used whenever a record is erased or removed in the db, however the problem
                 * it's that the same object is used every time, and the delete method invoked
                 * sets the _deleted attribute to true when its called, of course as we use
                 * the same object, the first time works fine but trowns an error with the
                 * next record, cos it's the same object and the delete method checks if the _deleted
                 * attribute it's true or false, the attrib _deleted is setted to true the
                 * first time and later is never changed, the issue seems to be part of
                 * every remove function in the model classes, not only DbSource
                 * i recommend that a more general solution must be achieved to resolve
                 * this issue in every model class, to prevent future problems.
                 */
                $oDbSource->remove($aRow['DBS_UID'], $sProcessUID);
                $oDataset->next();
            }
            //Delete the supervisors
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(ProcessUserPeer::PRO_UID, $sProcessUID);
            ProcessUserPeer::doDelete($oCriteria);
            //Delete the object permissions
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(ObjectPermissionPeer::PRO_UID, $sProcessUID);
            ObjectPermissionPeer::doDelete($oCriteria);
            //Delete the step supervisors
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(StepSupervisorPeer::PRO_UID, $sProcessUID);
            StepSupervisorPeer::doDelete($oCriteria);
            //Delete the report tables
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(ReportTablePeer::PRO_UID, $sProcessUID);
            $oDataset = ReportTablePeer::doSelectRS($oCriteria);
            $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $oDataset->next();
            while ($aRow = $oDataset->getRow()) {
                $oReportTable->deleteReportTable($aRow['REP_TAB_UID']);
                $oDataset->next();
            }
            //Delete case tracker configuration
            $oCaseTracker->remove($sProcessUID);
            //Delete case tracker objects
            $oCriteria = new Criteria('workflow');
            $oCriteria->add(CaseTrackerObjectPeer::PRO_UID, $sProcessUID);
            ProcessUserPeer::doDelete($oCriteria);
            //Delete the process
            try {
                $oProcess->remove($sProcessUID);
            } catch (Exception $oError) {
                throw ($oError);
            }
            return true;
        } catch (Exception $oError) {
            throw ($oError);
        }
    }
             $rpts->deleteReportTable($rptUid);
         }
         $sRepTabUid = "";
         break;
     case 2:
         //Delete table
         $rpts = new ReportTables();
         $rpts->dropTable($tableName, "wf");
         $sRepTabUid = "";
         break;
 }
 $criteria = new Criteria();
 $criteria->addSelectColumn(ReportTablePeer::REP_TAB_UID);
 //$criteria->add(ReportTablePeer::PRO_UID, $sProUid);
 $criteria->add(ReportTablePeer::REP_TAB_NAME, $tableName);
 $result = ReportTablePeer::doSelectRS($criteria);
 $result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
 if ($result->next()) {
     $dataRes = $result->getRow();
     if ($dataRes["REP_TAB_UID"] != $sRepTabUid) {
         return 1;
     }
 } else {
     //check if table $tableName exists
     $con = Propel::getConnection("workflow");
     $stmt = $con->createStatement();
     $sql = "SHOW TABLES";
     $rs1 = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM);
     $rs1->next();
     while (is_array($row = $rs1->getRow())) {
         if ($row[0] == $tableName) {