// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'data')));
$pgf = new PolicyGroupFactory();
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        $pgf->StartTransaction();
        $pgf->setId($data['id']);
        $pgf->setCompany($current_company->getId());
        $pgf->setName($data['name']);
        $pgf->setExceptionPolicyControlID($data['exception_policy_control_id']);
        if ($pgf->isValid()) {
            $pgf->Save(FALSE);
            if (isset($data['user_ids'])) {
                $pgf->setUser($data['user_ids']);
            } else {
                $pgf->setUser(array());
            }
            if (isset($data['over_time_policy_ids'])) {
                $pgf->setOverTimePolicy($data['over_time_policy_ids']);
            } else {
                $pgf->setOverTimePolicy(array());
            }
            if (isset($data['premium_policy_ids'])) {
                $pgf->setPremiumPolicy($data['premium_policy_ids']);
 function createPolicyGroup($company_id, $meal_policy_ids = NULL, $exception_policy_id = NULL, $holiday_policy_ids = NULL, $over_time_policy_ids = NULL, $premium_policy_ids = NULL, $rounding_policy_ids = NULL, $user_ids = NULL)
 {
     $pgf = new PolicyGroupFactory();
     $pgf->StartTransaction();
     $pgf->setCompany($company_id);
     $pgf->setName('Default');
     if ($exception_policy_id != '') {
         $pgf->setExceptionPolicyControlID($exception_policy_id);
     }
     if ($pgf->isValid()) {
         $insert_id = $pgf->Save(FALSE);
         if (is_array($meal_policy_ids)) {
             $pgf->setMealPolicy($meal_policy_ids);
         } else {
             $pgf->setMealPolicy(array());
         }
         if (is_array($over_time_policy_ids)) {
             $pgf->setOverTimePolicy($over_time_policy_ids);
         } else {
             $pgf->setOverTimePolicy(array());
         }
         if (is_array($premium_policy_ids)) {
             $pgf->setPremiumPolicy($premium_policy_ids);
         } else {
             $pgf->setPremiumPolicy(array());
         }
         if (is_array($rounding_policy_ids)) {
             $pgf->setRoundIntervalPolicy($rounding_policy_ids);
         } else {
             $pgf->setRoundIntervalPolicy(array());
         }
         if (is_array($holiday_policy_ids)) {
             $pgf->setHolidayPolicy($holiday_policy_ids);
         } else {
             $pgf->setHolidayPolicy(array());
         }
         if (is_array($user_ids)) {
             $pgf->setUser($user_ids);
         } else {
             $pgf->setUser(array());
         }
         if ($pgf->isValid()) {
             $pgf->Save();
             $pgf->CommitTransaction();
             Debug::Text('Creating Policy Group ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
             return TRUE;
         }
     }
     Debug::Text('Failed Creating Policy Group!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }