Example #1
0
    default:
        //if backup_restore_path is already set, we probobly dont want that any more. delete it
        if (isset($_SESSION['backup_restore_path'])) {
            unset($_SESSION['backup_restore_path']);
        }
        break;
}
//view actions
switch ($var['action']) {
    case 'browseserver':
        $content = load_view(dirname(__FILE__) . '/views/restore/browseserver.php', $var);
        break;
    case 'upload':
    case 'backup_list':
        $var['servers'] = backup_get_server('all');
        $var['templates'] = backup_get_template('all_detailed');
        //transalate variables
        //TODO: make this anonymous once we require php 5.3
        function callback(&$var)
        {
            $var = backup__($var);
        }
        array_walk_recursive($var['servers'], 'callback');
        array_walk_recursive($var['templates'], 'callback');
        if (is_array($_SESSION['backup_restore_path'])) {
            //TODO: if $var['restore_path'] is an array, that means it contains an error + error
            // message. Do something with the error meesage
            echo _('Invalid backup for or undefined error');
            break;
        }
        //try to get a manifest, and continue if we did
    $var['action'] = 'delete';
}
//action actions
switch ($var['action']) {
    case 'save':
        $var['id'] = backup_put_template($var);
        break;
    case 'delete':
        $var['id'] = backup_del_template($var['id']);
        break;
}
//view actions
switch ($var['action']) {
    case 'edit':
    case 'save':
        $var = array_merge($var, backup_get_template($var['id']));
        //template id's are all prefixed by their module name for hooking reasons. Clear that past this point
        if (strpos($var['id'], 'backup-') === 0) {
            $var['id'] = substr($var['id'], 7);
        }
        $content = load_view(dirname(__FILE__) . '/views/templates/template.php', $var);
        break;
    default:
        $content = load_view(dirname(__FILE__) . '/views/templates/templates.php', $var);
        break;
}
$heading = _("Templates");
?>

<div class="container-fluid">
	<h1><?php 
Example #3
0
 public function getRightNav($request)
 {
     $var = array();
     switch ($request['display']) {
         case 'backup':
             if (isset($request['action']) && $request['action'] == 'edit') {
                 $var['backup'] = backup_get_backup('all');
             }
             return load_view(dirname(__FILE__) . '/views/rnav/backup.php', $var);
             break;
         case 'backup_restore':
             $var['servers'] = backup_get_server('all');
             return load_view(dirname(__FILE__) . '/views/rnav/restore.php', $var);
             break;
         case 'backup_servers':
             if (isset($request['action']) && $request['action'] == 'edit') {
                 $var['servers'] = backup_get_server('all');
             }
             return load_view(dirname(__FILE__) . '/views/rnav/servers.php', $var);
             break;
         case 'backup_templates':
             if (isset($request['action']) && $request['action'] == 'edit') {
                 $var['templates'] = backup_get_template('all');
             }
             return load_view(dirname(__FILE__) . '/views/rnav/templates.php', $var);
             break;
     }
 }
Example #4
0
function backup_put_template($var)
{
    global $db, $amp_conf;
    //dont save protected templates
    if ($var['id']) {
        $stale = backup_get_template($var['id']);
        if ($stale['immortal'] == 'true') {
            return false;
        }
    }
    //save server
    if (!empty($var['id'])) {
        $sql = 'UPDATE backup_templates SET name = ?, `desc` = ? WHERE id = ?';
        $sql_params = array($var['name'], $var['desc'], $var['id']);
    } else {
        $sql = 'INSERT INTO backup_templates (name, `desc`) VALUES (?, ?)';
        $sql_params = array($var['name'], $var['desc']);
    }
    $ret = $db->query($sql, $sql_params);
    if ($db->IsError($ret)) {
        die_freepbx($ret->getDebugInfo());
    }
    $sql = $amp_conf["AMPDBENGINE"] == "sqlite3" ? 'SELECT last_insert_rowid()' : 'SELECT LAST_INSERT_ID()';
    $var['id'] = $var['id'] ? $var['id'] : $db->getOne($sql);
    //save server details
    //first delete stale
    $sql = 'DELETE FROM backup_template_details WHERE template_id = ?';
    $ret = $db->query($sql, $var['id']);
    if ($db->IsError($ret)) {
        die_freepbx($ret->getDebugInfo());
    }
    //prepare array for insertion
    $saved = array();
    if (is_array($var['type'])) {
        foreach ($var['type'] as $e_id => $type) {
            if (!isset($saved[$type], $saved[$type][$var['path'][$e_id]])) {
                //mark row as saved so that we can check for dups
                $saved[$type][$var['path'][$e_id]] = true;
                //ensure excludes are unique and clean
                if (!is_array($var['exclude'][$e_id])) {
                    $excludes = explode("\n", $var['exclude'][$e_id]);
                } else {
                    $excludes = $var['exclude'][$e_id];
                }
                foreach ($excludes as $my => $e) {
                    $excludes[$my] = trim($e);
                }
                $excludes = array_unique($excludes);
                $data[] = array($var['id'], $type, $var['path'][$e_id], serialize($excludes));
            }
        }
        //then insert fresh
        $sql = $db->prepare('INSERT INTO backup_template_details (template_id, type, path, exclude) VALUES (?, ?, ?, ?)');
        $ret = $db->executeMultiple($sql, $data);
        if ($db->IsError($ret)) {
            die_freepbx($ret->getDebugInfo());
        }
    }
    return $var['id'];
}