function addNewCProgram() { //--------------------------------------------------------------------- // //--------------------------------------------------------------------- global $glUserID; $cufc = new muser_fields_create(); // first make the new entry in the client program table $sqlStr = 'INSERT INTO cprograms SET ' . $this->strSQLCommon() . ",\n cp_bRetired = 0,\n cp_lOriginID = {$glUserID},\n cp_dteOrigin = NOW();"; $query = $this->db->query($sqlStr); $this->cprogs[0]->lKeyID = $lKeyID = $this->db->insert_id(); $strKeyID = str_pad($lKeyID, 5, '0', STR_PAD_LEFT); //--------------------------------- // add the enrollment table //--------------------------------- $cufc->bMultiEntry = true; $cufc->bReadOnly = $this->cprogs[0]->bETableReadOnly; $cufc->bCollapsibleHeadings = true; $cufc->bCollapseDefaultHide = true; $cufc->bAlertNoDataEntry = false; $cufc->strAlert = ''; $cufc->strTableDescription = 'Auto-generated for Client Program ' . $strKeyID; $cufc->strUserTableName = 'Client Programs Enrollment ' . $strKeyID; $cufc->enumTType = CENUM_CONTEXT_CPROGENROLL; $lEnrollTableID = $cufc->lTableID = $cufc->lAddNewUFTable(); $strEnrollTableName = $cufc->strENPTableName; $strFNPrefix = $cufc->strGenUF_KeyFieldPrefix($lEnrollTableID); $strClientIDFN = $strFNPrefix . '_lClientID'; $strDateStartFN = $strFNPrefix . '_dteStart'; $strDateEndFN = $strFNPrefix . '_dteEnd'; $strBEnrolledFN = $strFNPrefix . '_bCurrentlyEnrolled'; // note that the foreign ID in the personalized table is the client ID $sqlStr = "ALTER TABLE {$strEnrollTableName}\n ADD {$strDateStartFN} date NOT NULL,\n ADD {$strDateEndFN} date DEFAULT NULL,\n ADD {$strBEnrolledFN} tinyint(1) NOT NULL DEFAULT '0';"; $query = $this->db->query($sqlStr); //--------------------------------- // add the attendance table //--------------------------------- $cufc->strUserTableName = 'Client Programs Attendance ' . $strKeyID; $cufc->enumTType = CENUM_CONTEXT_CPROGATTEND; $cufc->bReadOnly = $this->cprogs[0]->bATableReadOnly; $lAttendTableID = $cufc->lTableID = $cufc->lAddNewUFTable(); $strAttendTableName = $cufc->strENPTableName; $strFNPrefix = $cufc->strGenUF_KeyFieldPrefix($lAttendTableID); $strEnrollIDFN = $strFNPrefix . '_lEnrollID'; $strDateAttendFN = $strFNPrefix . '_dteAttendance'; $strDurationFN = $strFNPrefix . '_dDuration'; $strCaseNotesFN = $strFNPrefix . '_strCaseNotes'; $sqlStr = "ALTER TABLE {$strAttendTableName}\n ADD {$strEnrollIDFN} INT NOT NULL COMMENT 'Foreign key to enrollment table',\n ADD {$strDateAttendFN} date NOT NULL,\n ADD {$strDurationFN} DECIMAL(10, 2) NOT NULL DEFAULT 0,\n ADD {$strCaseNotesFN} TEXT NOT NULL,\n ADD INDEX({$strEnrollIDFN}),\n ADD INDEX({$strDateAttendFN});"; $query = $this->db->query($sqlStr); //------------------------------------------------------------------ // add the activity DDL //------------------------------------------------------------------ $cufc->lTableID = $lAttendTableID; $cufc->fields = array(); $cufc->fields[0] = new stdClass(); $ufield =& $cufc->fields[0]; $ufield->enumFieldType = CS_FT_DDL; $ufield->pff_strFieldNameUser = '******'; $ufield->pff_bCheckDef = false; $ufield->pff_curDef = 0.0; $ufield->pff_strTxtDef = ''; $ufield->pff_lDef = 0; $ufield->pff_lCurrencyACO = 1; $ufield->pff_bHidden = false; $ufield->pff_bRequired = true; $cufc->addNewField(); $lDDLActivityFID = $ufield->pff_lKeyID; // add default activity $cufc->setDDL_asConfigured($lDDLActivityFID); $lNewSortIDX = 1; $lDDLEntryID = $cufc->addUF_DDLEntry('(other)', $lDDLActivityFID, $lNewSortIDX); //------------------------------------------------------------------ // update cprogram table with the enrollment/attendance table IDs //------------------------------------------------------------------ $sqlStr = "UPDATE cprograms\n SET\n cp_lEnrollmentTableID = {$lEnrollTableID},\n cp_lAttendanceTableID = {$lAttendTableID},\n cp_lActivityFieldID = {$lDDLActivityFID}\n WHERE cp_lKeyID={$lKeyID};"; $query = $this->db->query($sqlStr); return $lKeyID; }