Exemple #1
0
 public function restoreBackup($strFile = null)
 {
     global $_PATHS;
     $blnReturn = false;
     if (is_null($strFile)) {
         //*** Find the latest backup.
         $arrFiles = scandir($_PATHS['backup'], 1);
         foreach ($arrFiles as $strFileName) {
             if (substr($strFileName, 0, strlen($this->punchId) + 1) == $this->punchId . "_") {
                 $strFile = $strFileName;
                 break;
             }
         }
     }
     if (!empty($strFile) && is_file($strFile)) {
         ImpEx::import($strFile, true, true);
         $blnReturn = true;
     }
     return $blnReturn;
 }
Exemple #2
0
function parseAccount($eId, $cmd)
{
    global $_PATHS, $_CONF, $objUpload, $objLiveAdmin;
    $objTpl = new HTML_Template_IT($_PATHS['templates']);
    $objTpl->loadTemplatefile("account.tpl.htm");
    switch ($cmd) {
        case CMD_EDIT:
            $strDispatch = Request::get('dispatch');
            $intPermId = Request::get('frm_userid');
            $strPunchId = Request::get('frm_punchid');
            $strName = Request::get('frm_name');
            $strDomain = Request::get('frm_uri');
            $strUserName = Request::get('frm_account_name');
            $strUserPass = Request::get('frm_account_pass');
            $strUserEmail = Request::get('frm_account_email');
            //$arrProducts 	= Request::get('frm_account_product', array());
            $objAccount = Account::selectByPk($eId);
            if ($strDispatch == "editAccount") {
                if (is_object($objAccount)) {
                    $objAccount->setName($strName);
                    $objAccount->setUri($strDomain);
                    $objAccount->save();
                    //*** Set products.
                    $objAccount->clearProducts();
                    /*
                    foreach ($arrProducts as $intProduct) {
                    	$objAccount->addProduct($intProduct);
                    }
                    */
                    $objAccount->addProduct(1);
                    //*** Edit Admin user.
                    $data = array('name' => $strUserName, 'email' => $strUserEmail);
                    if (!empty($strUserPass)) {
                        $data['passwd'] = $strUserPass;
                    }
                    $objLiveAdmin->updateUser($data, $intPermId);
                    $objTpl->setCurrentBlock("text");
                    $objTpl->setVariable('BODY', "<p>Account saved successfully.</p>");
                    $objTpl->parseCurrentBlock();
                }
            } else {
                if (is_object($objAccount)) {
                    $strAdminName = "";
                    $strAdminEmail = "";
                    //*** Admin user.
                    $filters = array('container' => 'auth', 'filters' => array('account_id' => array($objAccount->getId())));
                    $objUsers = $objLiveAdmin->getUsers($filters);
                    if (is_array($objUsers)) {
                        foreach ($objUsers as $objUser) {
                            if ($objUser["perm_type"] == 4) {
                                $strAdminName = $objUser["name"];
                                $strAdminEmail = $objUser["email"];
                                $intPermId = $objUser["perm_user_id"];
                                break;
                            }
                        }
                    }
                    $objTpl->setCurrentBlock("form.field.punchid");
                    $objTpl->setVariable('PUNCH_ID_VALUE', $objAccount->getPunchId());
                    $objTpl->parseCurrentBlock();
                    /*
                    $objProducts = Product::getProducts();
                    $objAccountProducts = AccountProduct::getByAccountId($objAccount->getId());
                    foreach ($objProducts as $objProduct) {
                    	$objTpl->setCurrentBlock("form.field.product");
                    	$objTpl->setVariable('ID', $objProduct->getId());
                    	$objTpl->setVariable('LABEL', $objProduct->getName());
                    	$objTpl->setVariable('VALUE', $objProduct->getId());
                    	
                    	foreach ($objAccountProducts as $objAccountProduct) {
                    		if ($objAccountProduct->getProductId() == $objProduct->getId()) {
                    			$objTpl->setVariable('CHECKED', "checked=\"checked\"");
                    		}
                    	}
                    	
                    	$objTpl->parseCurrentBlock();
                    }
                    */
                    $objTpl->setCurrentBlock("form.edit");
                    $objTpl->setVariable('NAME_VALUE', $objAccount->getName());
                    $objTpl->setVariable('URI_VALUE', $objAccount->getUri());
                    $objTpl->setVariable('ACCOUNT_NAME_VALUE', $strAdminName);
                    $objTpl->setVariable('ACCOUNT_EMAIL_VALUE', $strAdminEmail);
                    $objTpl->setVariable('USER_ID', $intPermId);
                    $objTpl->setVariable('CID', NAV_ACCOUNT);
                    $objTpl->setVariable('EID', $eId);
                    $objTpl->setVariable('CMD', $cmd);
                    $objTpl->parseCurrentBlock();
                }
            }
            break;
        case CMD_ADD:
            $strDispatch = Request::get('dispatch');
            $strName = Request::get('frm_name');
            $strDomain = Request::get('frm_uri');
            $strUserName = Request::get('frm_account_name');
            $strUserPass = Request::get('frm_account_pass');
            $strUserEmail = Request::get('frm_account_email');
            //$arrProducts 	= Request::get('frm_account_product');
            if ($strDispatch == "editAccount") {
                //*** Generate new punchId.
                $strPunchId = Account::generateId();
                $objAccount = new Account();
                $objAccount->setPunchId($strPunchId);
                $objAccount->setName($strName);
                $objAccount->setUri($strDomain);
                $objAccount->setTimeZoneId(42);
                $objAccount->save();
                //*** Set products.
                $objAccount->clearProducts();
                /*
                foreach ($arrProducts as $intProduct) {
                	$objAccount->addProduct($intProduct);
                }
                */
                $objAccount->addProduct(1);
                //*** Add Admin user to the account.
                $data = array('handle' => 'admin', 'name' => $strUserName, 'passwd' => $strUserPass, 'is_active' => true, 'email' => $strUserEmail, 'account_id' => $objAccount->getId(), 'perm_type' => 4);
                $intPermId = $objLiveAdmin->addUser($data);
                $strOutput = "<p>Account successfully created.</p>\n";
                $strOutput .= "<p>PunchId: <b>{$objAccount->PunchId}</b></p>\n";
                $objTpl->setCurrentBlock("text");
                $objTpl->setVariable('BODY', $strOutput);
                $objTpl->parseCurrentBlock();
            } else {
                /*
                $objProducts = Product::getProducts();
                foreach ($objProducts as $objProduct) {
                	$objTpl->setCurrentBlock("form.field.product");
                	$objTpl->setVariable('ID', $objProduct->getId());
                	$objTpl->setVariable('LABEL', $objProduct->getName());
                	$objTpl->setVariable('VALUE', $objProduct->getId());
                	$objTpl->parseCurrentBlock();
                }
                */
                $objTpl->setCurrentBlock("form.edit");
                $objTpl->setVariable('CID', NAV_ACCOUNT);
                $objTpl->setVariable('EID', $eId);
                $objTpl->setVariable('CMD', $cmd);
                $objTpl->parseCurrentBlock();
            }
            break;
        case CMD_IMPORT:
            $strDispatch = Request::get('dispatch');
            $blnOverwrite = Request::get('frm_import_overwrite') == "true" ? true : false;
            $blnKeepSettings = Request::get('frm_import_keep_settings') == "true" ? true : false;
            if ($strDispatch == "importAccount") {
                if (empty($_FILES['frm_file']['name'])) {
                    $strOutput = "<p>Error importing the file. It's empty...</p>";
                } else {
                    if (is_uploaded_file($_FILES['frm_file']['tmp_name'])) {
                        $objAccount = ImpEx::import($_FILES['frm_file']['tmp_name'], $blnOverwrite, $blnKeepSettings);
                        if (is_object($objAccount)) {
                            $strOutput = "<p>Account for <b>{$objAccount->getName()}</b> has been imported successfully with PunchId <b>{$objAccount->PunchId}</b>.</p>\n";
                        } else {
                            $strOutput = "<p>Import failed! Check the XML and try again.</p>\n";
                        }
                    }
                }
                $objTpl->setCurrentBlock("text");
                $objTpl->setVariable('BODY', $strOutput);
                $objTpl->parseCurrentBlock();
            } else {
                $objTpl->setCurrentBlock("form.import");
                $objTpl->setVariable('CID', NAV_ACCOUNT);
                $objTpl->setVariable('CMD', $cmd);
                $objTpl->parseCurrentBlock();
            }
            break;
        case CMD_EXPORT:
            $strDispatch = Request::get('dispatch');
            $blnFiles = Request::get('frm_export_files') == "true" ? "1" : "0";
            if ($strDispatch == "exportAccount" && $eId > 0) {
                Request::redirect("/export.php?eid=" . $eId . "&files=" . $blnFiles);
            } else {
                $objTpl->setCurrentBlock("form.export");
                $objTpl->setVariable('CID', NAV_ACCOUNT);
                $objTpl->setVariable('CMD', $cmd);
                $objTpl->setVariable('EID', $eId);
                $objTpl->parseCurrentBlock();
            }
            break;
        case CMD_RESTORE:
            $strDispatch = Request::get('dispatch');
            $strBackupName = Request::get('frm_backup');
            $objAccount = Account::selectByPk($eId);
            if ($strDispatch == "restoreAccount") {
                if (is_object($objAccount)) {
                    if ($objAccount->restoreBackup($_PATHS['backup'] . $strBackupName)) {
                        $strOutput = "<p>Account successfully restored.</p>\n";
                    } else {
                        $strOutput = "<p>Errors occured while restoring the account.</p>\n";
                    }
                    $objTpl->setCurrentBlock("text");
                    $objTpl->setVariable('BODY', $strOutput);
                    $objTpl->parseCurrentBlock();
                }
            } else {
                if (is_object($objAccount)) {
                    $objBackups = $objAccount->getBackups();
                    foreach ($objBackups as $objBackup) {
                        $objTpl->setCurrentBlock("form.field.backup");
                        $objTpl->setVariable('VALUE', $objBackup["file"]);
                        $objTpl->setVariable('LABEL', $objBackup["label"]);
                        $objTpl->parseCurrentBlock();
                    }
                    $objTpl->setCurrentBlock("form.restore");
                    $objTpl->setVariable('ACCOUNT_VALUE', $objAccount->getName());
                    $objTpl->setVariable('CID', NAV_ACCOUNT);
                    $objTpl->setVariable('EID', $eId);
                    $objTpl->setVariable('CMD', $cmd);
                    $objTpl->parseCurrentBlock();
                }
            }
            break;
    }
    //*** Return the output.
    return $objTpl->get();
}