function build_manager_form($curusr, $action)
{
    $types = new DataBaseTable('types', true, DATACONF);
    $tq = $types->getData("ctype:`note`");
    $qstr = "section={$action}";
    $type_opts = null;
    $siteroot = SITEROOT;
    if ($action == 'edit' && !empty($_GET['nid'])) {
        $asave = " autoSave";
        $nt = new DataBaseTable('notes', true, DATACONF);
        $nq = $nt->getData("nid:`= {$_GET['nid']}`");
        $values = $nq->fetch(PDO::FETCH_ASSOC);
        $values['modified'] = date("Y-m-d H:i:s");
        $qstr = $qstr . "&nid={$values['nid']}";
    } else {
        $asave = null;
        $values['uid'] = $curusr->uid;
        $values['cid'] = $_GET['cid'];
        $values['created'] = date("Y-m-d H:i:s");
        $values['modified'] = null;
        $values['note'] = "<p>Write your note here...</p>";
    }
    while ($type = $tq->fetch(PDO::FETCH_ASSOC)) {
        $selected = null;
        if ($type['ttid'] == $values['ttid']) {
            $selected = " selected=\"selected\"";
        }
        $type_opts .= "<option{$selected} value=\"{$type['ttid']}\">{$type['name']}</option>\n";
    }
    return <<<HTML
<form action="{$siteroot}dash/?{$qstr}" class="manager{$asave}" method="post">
<div class="form-group">
<label for="title">Note Title</label>
<input type="hidden" name="uid" value="{$values['uid']}">
<input type="hidden" name="cid" value="{$values['cid']}">
<input type="hidden" name="created" value="{$values['created']}">
<input type="hidden" name="modified" value="{$values['modified']}">
<input id="title" class="form-control" name="title" value="{$values['title']}">
</div>
<div class="form-group">
<label for="ttid">Type</label>
<select class="form-control" name="ttid">
{$type_opts}
</select>
</div>
<div class="form-group">
<label for="note">Note Text (full formatting available)</label>
<textarea class="form-control full editor" name="note">
{$values['note']}
</textarea>
</div>
<div class="form-group center">
<button class="btn btn-primary" type="button" data-target="#messageModal" name="save" value="1">Save</button>
<a href="{$siteroot}view/note/{$_GET['nid']}" class="btn btn-info">View</a>
<a href="{$siteroot}print/note/{$_GET['nid']}" class="btn btn-info">Print</a>
<a href="{$siteroot}dash/?section=projects" class="btn btn-danger" data-target="#this-modal">Cancel</a>
</div>
HTML;
}
function find_cid(array $titles, $parent = 0, $offset = 0)
{
    $con = new DataBaseTable('content', true, DATACONF);
    $cq = $con->getData("title:`{$titles[$offset]}` pid:`= {$parent}`", array('cid', 'title'));
    $ci = $cq->fetch(PDO::FETCH_OBJ);
    $offset++;
    if (!empty($titles[$offset])) {
        return find_cid($titles, $ci->cid, $offset);
    } else {
        return $ci->cid;
    }
}
function list_projects(MCSession $curusr, $filter = null)
{
    $table = new DataBaseTable('content', true, DATACONF);
    $q = "pid:`= 0`";
    if (!empty($filter)) {
        $q .= " " . $filter;
    }
    $q = $table->getData($q, null, null, $curusr->items_per_page, $_GET['offset']);
    $cols = $curusr->items_per_page / $curusr->rows_per_page;
    if ($q instanceof PDOStatement) {
        $grid = con_list_to_grid($q);
        $list = "<div id=\"ConList\" class=\"grid grid-col-{$cols}\">\n";
    }
    if (empty($grid)) {
        if (empty($curusr) || $curusr->level >= 3) {
            $html = "<div class=\"alert alert-warning\">No Content Posted! Please <a href=\"" . SITEROOT . "/?modal=login\">login</a> and post some stuff!!</div>";
        } else {
            $html = "<div class=\"alert alert-warning\">No Content Posted! Please open the <a href=\"" . SITEROOT . "dash/?section=projects\" data-toggle=\"modal\" data-target=\"#AJAXModal\">project manager</a> to add new content!</div>";
        }
    } else {
        $html = $list;
    }
    return $html;
}
Example #4
0
#!/usr/bin/php

<?php 
require dirname(__FILE__) . "/appcore/dataconnect/database.inc.php";
fwrite(STDOUT, "Welcome to the Web Comic Manager!\n\nHere you will be able to perform basic functions and data manipulation as if you were logged in as an administrator. Please note: this program may present a security risk. In highly secure production environments it is a good idea to remove this file.\n");
fwrite(STDOUT, "What would you like to do?\n");
fwrite(STDOUT, "1) Look up, view, or edit a user\n");
fwrite(STDOUT, "0) Erase ALL data!\n");
$select = fgets(STDIN);
switch ($select) {
    case 1:
        $table = new DataBaseTable('users');
        fwrite(STDOUT, "Search query (press enter to look up all users): ");
        $query = fgets(STDIN);
        $query = $table->getData($query);
        while ($row = $query->fetch(PDO::FETCH_OBJ)) {
            fwrite(STDOUT, $row->id . "|" . $row->name . "|" . $row->email . "\n");
        }
        fwrite(STDOUT, "Select a user's id: ");
        $id = trim(fgets(STDIN), "\n");
        if (!is_numeric($id)) {
            exit;
        } else {
            $query = $table->getData("id:'= {$id}'");
            $user = $query->fetch(PDO::FETCH_ASSOC);
            foreach ($user as $key => $value) {
                if ($key == 'password') {
                    $value = "****";
                }
                fwrite(STDOUT, $key . ": " . $value . "\n");
            }
Example #5
0
                while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
                    $projects .= con_to_html($row);
                    $c++;
                }
            }
            if ($c <= 0) {
                $body .= "<div class=\"alert alert-warning\">You have no projects! Would you like to <a href=\"//{$conf->base_uri}/dash/?section=put&type=project\" data-target=\"#this-modal\">add one</a>?</div>\n";
            } else {
                $body .= "<div id=\"List\" class=\"panel-group\">\n{$projects}\n</div>\n<span class=\"alert alert-info\">You have {$c} project(s). <a href=\"./dash.php?section=put&type=project\" data-target=\"#this-modal\">Add another</a>?</span> <a href=\"javascript:location.reload()\" class=\"right btn btn-info\">Reload Index</a>\n";
            }
    }
}
if (!empty($_GET['json'])) {
    header("Content-type:'text/json'");
    $return_arr['okay'] = $success;
    $return_arr['message'] = $message;
    echo json_encode($return_arr);
} elseif (!empty($_GET['section'] == "author-search")) {
    $udb = new DataBaseTable('users', true, DATACONF);
    $uq = $udb->getData("name:`%{$_GET['q']}%`");
    echo json_encode($uq->fetchALL(PDO::FETCH_ASSOC));
} else {
    echo <<<HTML
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">{$title}</h4></div>
<div class="modal-body">
<script src="//{$conf->base_uri}/appcore/scripts/ajaxlinks.js" type="text/javascript"></script>
{$body}
</div>
HTML;
}
Example #6
0
        $attachment = 'download';
    }
    $type = $path_parts[2];
    if ($type != 'content') {
        $type = $type . "s";
    }
    $id = $path_parts[3];
    $format = $path_parts[4];
} else {
    foreach ($_GET as $var => $val) {
        ${$var} = $val;
    }
}
$db = new DataBaseTable($type, true, DATACONF);
$col = substr($type, 0, 1) . "id";
$q = $db->getData($col . ":`= {$id}`");
$data = $q->fetch(PDO::FETCH_OBJ, PDO::FETCH_ORI_FIRST);
if (!empty($data->file)) {
    header("Location: //{$conf->base_uri}/{$data->file}");
} elseif ($type == 'content') {
    $doc = $data->data;
} else {
    $doc = $data->{$path_parts}[2];
}
if (!empty($attachment) && $attachment == 'download') {
    $filename = storagename($data->title);
    switch ($format) {
        /*case 'word':
          header ("Content-Type: application/msword");
          $filename.=".doc";
          TODO reformat $doc? create other formats?
function con_list_to_grid($q, $showprivate = false)
{
    $art = new DataBaseTable('art', true, DATACONF);
    while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
        if ($showprivate || con_is_public($row['cid'])) {
            $aq = $art->getData("cid:`= {$row['cid']}`", array('ttid', 'uri'));
            $arts = array();
            while ($cover = $aq->fetch(PDO::FETCH_ASSOC)) {
                $types = new DataBaseTable('types', true, DATACONF);
                $tq = $types->getData("ttid:`= {$cover['ttid']}`");
                $tinfo = $tq->fetch(PDO::FETCH_ASSOC);
                if ($tinfo['ctype'] == 'art') {
                    $arts[] = array('file' => $cover['uri'], 'type' => $tinfo['name']);
                }
            }
            $path = build_con_path($row['cid']);
            if (con_is_public($row['cid'])) {
                $access = "public";
                $href = SITEROOT . $path;
            } else {
                $access = "private";
                $href = SITEROOT . $path . "/?modal=private";
            }
            $list .= "<div id=\"{$row['cid']}\" class=\"proj {$access} grid-item\"><a href=\"{$href}\">\n";
            if ($arts[0]['type'] == "Front Cover") {
                $list .= "<figure class=\"figure\">\n<img src=\"" . SITEROOT . "{$arts[0]['file']}?type=image/png&w=350\" width=\"350\" class=\"proj-cover figure-img img-fluid img-round\" alt=\"[cover]\">\n<figcaption class=\"proj-title figure-caption text-center\">{$row['title']}</figcaption>\n</figure>\n";
            } else {
                $list .= "<h3 class=\"proj-title\">{$row['title']}</h3>\n<p class=\"proj-description\">{$row['data']}</p>\n";
            }
            $list .= "</a></div>\n";
            $c++;
        }
    }
    return $list;
}
function build_manager_form(MCSession $session, $action, $ctype = null, $pid = null, $cid = null)
{
    $con = new DataBaseTable('content', true, DATACONF);
    $siteroot = SITEROOT;
    if ($action != 'drop') {
        $types = new DataBaseTable('types', true, DATACONF);
        if ($action == 'update' && $cid != NULL) {
            $asave = " autoSave";
            $q = $con->getData("cid:`{$cid}`");
            $values = $q->fetch(PDO::FETCH_ASSOC);
            $values['modified'] = date("Y-m-d H:i:s");
            $child_btn = <<<HTML
<a href="{$siteroot}dash/?section=put&pid={$values['cid']}" class="btn btn-success" data-target="#this-modal">Add Child</a>
HTML;
            if (empty($ctype)) {
                $cttid = $types->getData("ttid:`= {$values['ttid']}`");
                $cttid = $cttid->fetch(PDO::FETCH_ASSOC);
                $ctype = $cttid['ctype'];
            }
            $qstr = "?section={$action}&cid={$cid}";
        } else {
            $ttid_opts .= "</select>\n";
            $asave = null;
            if (empty($pid)) {
                $values['pid'] = 0;
            } else {
                $values['pid'] = $pid;
            }
            $child_btn = null;
            $values['created'] = date("Y-m-d H:i:s");
            $values['modified'] = null;
            $values['title'] = "New " . ucwords($ctype);
            $values['uid'] = $session->uid;
            $values['tags'] = null;
            $values['ttid'] = null;
            $values['price'] = "0.00";
            $values['data'] = "<p>Your text here...</p>";
            $values['file'] = null;
            $qstr = "?section={$action}&type={$ctype}";
        }
        if (empty($ctype) && !empty($pid)) {
            $parent = $con->getData("cid:`= {$pid}`", array('ttid'));
            $parent = $parent->fetch(PDO::FETCH_ASSOC);
            $ptype = $types->getData("ttid:`= {$parent['ttid']}`");
            $ptype = $ptype->fetch(PDO::FETCH_ASSOC);
            $ctype = $ptype['child_types'];
        }
        if (empty($ctype)) {
            $ctype = "project";
        }
        $html = "<h4>{$action} {$ctype}</h4>\n";
        $ttids = $types->getData("ctype:`{$ctype}`");
        $ttid_opts = "<select class=\"form-control\" id=\"ttid\" name=\"ttid\">\n";
        while ($type = $ttids->fetch(PDO::FETCH_ASSOC)) {
            if ($type['ttid'] == $values['ttid']) {
                $tval = " selected=\"selected\"";
            } else {
                $tval = null;
            }
            $ttid_opts .= "<option{$tval} value=\"{$type['ttid']}\">{$type['name']}</option>\n";
        }
        $ttid_opts .= "</select>\n";
        switch ($ctype) {
            case 'note':
                $type_extras = <<<HTML
<div class="form-group">
<label for="note">Note</label>
<textarea id="note" name="data" class="full editor">
{$values['data']}
</textarea>
</div>
HTML;
                break;
            case 'art':
                break;
            case 'page':
                $type_extras = <<<HTML
<div class="form-group">
<label for="script">Script</label>
<textarea id="script" name="data" class="script editor form-control">
{$values['data']}
</textarea>
</div>
HTML;
                break;
            case 'section':
            case 'chapter':
            case 'project':
            default:
                $type_extras = <<<HTML
<div class="form-group">
<label for="description">Description</label>
<textarea id="description" name="data" class="limited editor form-control">
{$values['data']}
</textarea>
</div>
HTML;
        }
        $html .= <<<HTML
<form action="{$siteroot}dash/{$qstr}" class="manager{$asave}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title</label>
<input type="hidden" name="pid" value="{$values['pid']}">
<input type="hidden" name="uid" value="{$values['uid']}">
<input type="hidden" name="created" value="{$values['created']}">
<input type="hidden" name="modified" value="{$values['modified']}">
<input type="text" class="form-control" maxlength="160" id="title" name="title" value="{$values['title']}">
</div>
<div class="form-group">
<label for="price">Price</label>
<div class="input-group">
<span class="input-group-addon">\$</span><input type="number" class="form-control" maxlength="7" id="price" name="price" value="{$values['price']}"><span class="input-group-addon">USD</span>
</div>
</div>
<div class="form-group">
<label for="tags">Tags</label>
<input type="text" class="form-control" id="tags" name="tags" value="{$values['tags']}">
</div>
<div class="form-group">
<label for="ttid">Type</label>
{$ttid_opts}
</div>
<div id="Preferences">
{$type_extras}
</div>
<div class="form-group center">
<button class="btn btn-primary" type="button" data-target="#messageModal" name="save" value="1">Save</button>
{$child_btn}
<a href="{$siteroot}dash/?secton=projects" class="btn btn-danger" data-target="#this-modal">Cancel</a>
</div>
</form>
HTML;
        if ($action == 'update') {
            $children = $con->getData("pid:`= {$values['cid']}`");
            $cc = 0;
            $cdiv = null;
            while ($crow = $children->fetch(PDO::FETCH_ASSOC)) {
                $cdiv .= con_to_html($crow);
                $cc++;
            }
            if ($cc > 1) {
                $html .= "<div class=\"panel-group\">\n{$cdiv}\n</div>\n";
            } elseif ($cc == 1) {
                $html .= $cdiv;
            }
        }
    } else {
        $html = <<<HTML
<form action="{$siteroot}dash/?section=drop&cid={$cid}" method="post">
<div class="panel panel-danger">
<div class="panel-heading">Are you sure?</div>
<div class="panel-body">Are you really sure you want to drop this item? This action cannot be undone no matter how much you complain or wine</div>
<div class="panel-footer">
<input type="hidden" name="cid" value="{$_GET['cid']}">
<button type="button" class="btn btn-danger" data-target="#messageModal" name="confirm" value="1">Yes</button>
<a href="{$siteroot}dash/?section=projects" class="btn btn-info" data-target="#this-modal">No</a>
</div>
</div>
HTML;
    }
    return $html;
}
function build_manager_form($curusr, $action)
{
    $type = new DataBaseTable('types', true, DATACONF);
    $siteroot = SITEROOT;
    switch ($action) {
        case 'upload':
            $tq = $type->getData("ctype:`art`");
            $type_opts = null;
            while ($tr = $tq->fetch(PDO::FETCH_ASSOC)) {
                $type_opts .= "<option value=\"{$tr['ttid']}\">{$tr['name']}</option>\n";
            }
            $values['uid'] = $curusr->uid;
            if (!empty($_GET['cid'])) {
                $values['cid'] = $_GET['cid'];
            } else {
                $values['cid'] = 1;
            }
            $values['created'] = date("Y-m-d H:i:s");
            return <<<HTML
<form action="{$siteroot}dash/?section=upload" method="post" target="file-target" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title</label>
<input type="hidden" name="uid" value="{$values['uid']}">
<input type="hidden" name="cid" value="{$values['cid']}">
<input type="hidden" name="created" value="{$values['created']}">
<input id="title" type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label for="type">Type</label>
<select id="type" class="form-control" name="ttid">
{$type_opts}
</select>
</div>
<div class="form-group">
<label for="file">File</label>
<div class="input-group">
<label class="input-group-btn">
<span class="btn btn-primary">
Choose File <input id="file" type="file" style="display:none" name="art">
</span>
</label>
<input type="text" class="form-control" disabled="disabled">
</div>
<div id="art" class="progress no-show">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin=0 aria-valuemax="100">
<span class="sr-only">0%</span>
</div>
<input type="hidden" id="uriTarget" name="temp_name">
</div>
</div>
<div class="form-group center">
<button class="btn btn-primary" disabled=disabled type="button" data-target="#messageModal" name="save" value="1">Save</button>
<a href="{$siteroot}dash/?section=projects" class="btn btn-danger" data-target="#this-modal">Cancel</a>
</div>
</form>
<iframe name="file-target" class="no-show"></iframe>
HTML;
            break;
        case 'remove':
            break;
        case 'view':
        default:
            /*Art Info*/
            $art = new DataBaseTable('art', true, DATACONF);
            $art = $art->getData("aid:`= {$_GET['aid']}`");
            $art = $art->fetch(PDO::FETCH_OBJ);
            /*Author Info*/
            $users = new DataBaseTable('users', true, DATACONF);
            $author = $users->getData("uid:`= {$art->uid}`");
            $author = $author->fetch(PDO::FETCH_ASSOC);
            $author = $author['name'];
            /*Parent Info*/
            $content = new DataBaseTable('content', true, DATACONF);
            $parent = $content->getData("cid:`= {$art->cid}`");
            $parent = $parent->fetch(PDO::FETCH_ASSOC);
            $parent = $parent['title'];
            /*Type Info*/
            $tq = $type->getData("ttid:`= {$art->ttid}`");
            $tinfo = $tq->fetch(PDO::FETCH_ASSOC);
            $tname = $tinfo['name'];
            return <<<HTML
   <div id="View-{$art->aid}">
   <a href="{$siteroot}{$art->uri}" target="_new" title="open '{$art->title}' in new tab"><img src="{$siteroot}{$art->uri}?type=image/png&w=300" width="300" align="left" alt="{$art->title}">
   <h4>{$art->title}</h4></a>
   <ul class="nobullet noindent">
   <li><strong>Created: </strong>{$art->created}</li>
   <li><strong>Modified: </strong>{$art->modified}</li>
   <li><strong>Created by: </strong>{$author}</li>
   <li><strong>Type: </strong>{$tname}</li>
   <li><strong>Linked to: </strong>{$parent}</li>
   </ul>
   </div>
   <div class="center">
   <a href="{$siteroot}dash/?section=projects" class="btn btn-primary" data-target="#this-modal">Back</a>
   <button data-dismiss="modal" class="btn btn-info">Close Dialog</button>
   </div>
HTML;
    }
}
Example #10
0
function view_doc($type, $id)
{
    $table = new DataBaseTable($type . "s", true, DATACONF);
    $col = substr($type, 0, 1) . "id";
    $q = $table->getData($col . ":`= " . $id);
    $siteroot = SITEROOT;
    $doc = $q->fetch(PDO::FETCH_ASSOC);
    return <<<HTML
<h2>{$doc['title']}</h2>
<div class="left" style="width:1em"><a href="{$siteroot}save/{$type}/{$id}/html"><span class="glyphicon glyphicon-save" title="Download"></span></a> <a href="{$siteroot}print/{$type}/{$id}"><span class="glyphicon glyphicon-print" title="Print"></span></a></div>
<div id="DocViewer" class="page" style="width:95%">
{$doc['note']}
</div>
HTML;
}
function search_form($full = false)
{
    $siteroot = SITEROOT;
    $form = "<form action=\"" . SITEROOT . "search/\" method=\"get\">\n<div class=\"form-group\"><label for=\"query\">Text (in title or description)</label><input type=\"search\" class=\"form-control\" name=\"q\">\n</div>\n";
    if ($full == TRUE) {
        $tdb = new DataBaseTable('tags', true, DATACONF);
        $tq = $tdb->getData();
        while ($tag = $tq->fetch()) {
            $filters .= "<div class=\"grid-item\"><input id=\"t-{$tag['tid']}\" type=\"checkbox\" name=\"tags[]\" value=\"{$tag['tid']}\"> <label for=\"t-{$tag['tid']}\" class=\"tag tag-{$tag['type']}\">{$tag['name']}</label></div>\n";
        }
        $form .= <<<HTML
<script language="javascript">
\$(function(){
 \$("input#author").keyup(function(){
  \$.get('{$siteroot}dash/?section=author-search&q='+\$("input#author").val(),function(data){
   \$("#authors").html('');
   for(var i=0;i<data.length;i++){
    \$("#authors").append('<option value="'+data[i].name+'"></option>');
   }
  },'json');
 });
});
</script>
<div class="alert alert-info">Did you know you can perform most advanced searches with just the above textbox? It's true!</div>
<div class="form-group">
<label for="author">Author:</label><input type="text" list="authors" class="form-control" name="author" id="author">
<datalist id="authors">
</datalist>
</div>
<div class="form-group">
<label for="tags">Tags:</label>
<div id="tags" class="grid grid-col-4">
{$filters}
</div>
</div>
<div class="form-group">
<label for="cdate">Date Posted:</label>
<div class="input-group">
<span class="input-group-addon">Between</span>
<input type="date" id="cdate" class="form-control" name="date-created[min]">
<span class="input-group-addon">and</span>
<input type="date" class="form-control" name="date-created[max]">
</div>
</div>
<div class="form-group">
<label for="mdate">Date Modified:</label>
<div class="input-group">
<span class="input-group-addon">Between</span>
<input type="date" id="mdate" class="form-control" name="date-modified[min]">
<span class="input-group-addon">and</span>
<input type="date" id="mdate2" class="form-control" name="date-modified[max]">
</div>
</div>
<div class="form-group">
<label for="price-min">Price:</label>
<div class="input-group">
<span class="input-group-addon">Between</span>
<input type="number" id="price-min" class="form-control" placeholder="Min:" name="price[min]">
<span class="input-group-addon">and</span>
<input type="number" id="price-max" class="form-control" placeholder="Max:" name="price[max]">
</div>
</div>
HTML;
    }
    $form .= "<div class=\"center\">\n<button class=\"btn btn-primary\" type=submit\"><span class=\"glyphicon glyphicon-search\"></span> Search</button>\n</form>\n";
    return $form;
}