<?php
/* Ulyxex version 1.6.8.0 ***************/
/* code http://ulyxex.logz.org **********/
/* Andre Lozano http://andre-lozano.org */
class PageAdd extends Admin {
public object $tree;
function __construct(){
$this->h = New Htmlz();
$this->t = New Translate();
$this->tree = New Tree();
}
public function add_page_form(){
$h = $this->h;$t = $this->t;
$_[] = "<div ".$h->v("class","admincontent").">";// start admincontent
$_[] = $h->input("hidden","add",1);
$_[] = $h->p( $h->lbl($t->wr("child page of"),"parent").$this->tree->pathsSelect(null,1,"page") );
$_[] = $h->p(
$h->lbl($t->wr("redirect to link"),"link").
$h->input("text","link","",$h->v("size",round(FIELDWIDTH/1.5)).$h->v("class","admintext").$h->tit($t->w("def redirect link")))
);
$langsNames = array(
"en"=>"English","zh"=>"Chinese","hi"=>"Hindi","es"=>"Spanish","ar"=>"Arabic","fr"=>"French","bn"=>"Bengali",
"ru"=>"Russian","pt"=>"Portuguese","id"=>"Indonesian"
);
asort($langsNames);
foreach($langsNames as $iso=>$name) {$options[$iso.SP.$h->brkt($name)] = $iso;}
$select = $h->select($options,"langs",$t->getLang(),$h->v("onchange","updateBasicLang(this.value)"));
$defType = ($_SESSION['level'] < 2)?$h->lbl($t->wlr("or add new type"),"type").$h->input("text","type","",$h->v("class","admintext").$h->tit($t->w("def new type"))):"";
$_[] = $h->p(
$h->lbl(
$t->wr("type").$t->wr("page"),"set_type",$h->tit($t->w("references types pages"))
).
$h->select($this->getPageTypes(),"set_type","page",$h->tit($t->w("references types pages"))).
$defType." -- ".
$h->lbl($t->wlr("lang"),"lang").$h->input("text","lang",$t->getLang(),$h->v("size","3").$h->v("class","centered")).SP.
$select
);
$optionssort = array($t->w("date")=>0,$t->w("subject")=>1,$t->w("reverse date")=>2);
$optionspriority = array($t->w("none")=>"99");// DEFAULT VALUE
for ($i=1; $i < 51; $i++){
$optionspriority["^".sprintf("%'02d", $i)] = sprintf("%'02d", $i);
}
$priority = ($_SESSION['level'] < 2)?" -- ".$h->lbl($t->wlr("priority").$t->wr("page"),"priority").$h->select($optionspriority,"priority"):"";
$_[] = $h->p(
$h->lbl($t->wr("sort articles by"),"sortstyle").$h->select($optionssort,"sortstyle").
$h->lbl($t->wlr("hide").$t->wr("page"),"hide").$h->input("checkbox","hide","on").
$priority
);
$_[] = $h->p( $h->lbl($h->span("<title>",$h->v("class","htmtag")),"name") );
$_[] = $h->p( $h->input("text","name","",$h->v("size",round(FIELDWIDTH/1.3)).$h->v("class","admintext").$h->tit($t->w("def title tag"))) );
$_[] = $h->p(
$h->span("</title>",$h->v("class","htmtag")).SP.
$h->lbl($t->wr("allow duplicate this title"),"forcename").$h->input("checkbox","forcename")
,$h->tit($t->w("duplicate title")));
$_[] = $h->p( $h->lbl($h->span("<head>",$h->v("class","htmtag")),"head") );
$_[] = $h->p( $h->textarea("","head",array(3,FIELDWIDTH),$h->v("class","admintext").$h->tit($t->w("def head"))) );
$_[] = $h->p( $h->span(" </head>",$h->v("class","htmtag")) );
$_[] = $h->p(
$h->span("<body> <header> ".
$h->lbl($t->w("top content"),"content"),$h->v("class","htmtag")).SP.
$h->input("submit",null,$t->w("save")),
$h->tit($t->w("top content before articles"))
);
$_[] = $h->p(
$h->lbl($t->wr("add file"),"addfile").$h->input("file","addfile","",$h->v("size","30")).$t->wlr("or").
$h->ahref("admin.php?action=list_files",$t->w("list files in a new tab"),$h->v("target","blank").$h->v("class","linkbtn"))
);
$_[] = "</div>\n";// end admincontent
$_[] = $h->div(
$h->p(
$h->textarea("","content",array(20,FIELDWIDTH*2)),$h->tit($t->w("top content before articles"))
)
,$h->v("class","pagecontent"));
$_[] = "<div ".$h->v("class","admincontent").">";// start admincontent
$_[] = $h->p( $h->span("</header> ... ".$t->w("articles related")." ... </body>",$h->v("class","htmtag")).SP.$h->input("submit",null,$t->w("save")) );
$_[] = "</div>\n";// end admincontent
$inputs = implode("",$_);
return "</div>\n".$h->form($inputs,"page","post","admin.php?action=add_page","multipart/form-data")."<div ".$h->v("class","admincontent").">";
}
public function add_page(){
$h = $this->h;$t = $this->t;
if ($this->pageNameExist($h->safe(strip_tags($_POST['name']))) && !isset($_POST['forcename'])) {
return $h->h3($t->w("the name is already taken!"),$h->v("class","warning"));
}
$dt = new DateTime("now", new DateTimeZone(TIMEZONE));
$date = $dt->format('Y-m-d H:i:s');
$hide = (isset($_POST['hide']))?1:0;
if (!empty($_FILES['addfile']["name"])) {
$fileName = $_FILES['addfile']["name"];
$ext = $h->get_ext($fileName);
if ( !in_array($ext, $h->extUploadAllowed()) && $_SESSION['level'] > 1) exit("file extension not allowed ! ".$ext);// accept all file in level 1
$fileName = sprintf("%03d",rand(0,999))."_".$h->text2ascii($fileName);
$sendFile = move_uploaded_file($_FILES['addfile']["tmp_name"],"files/".$fileName);
if ($sendFile) {
$query = INSERTINTO.FILES." (FILENAME,USERID,DATEFILE) VALUES (".
"'"."files/".$fileName."',".$h->num($_SESSION['userid']).
",'".$date."');";
$query = $this->q($query);
$addFile = $h->br($h->getByFileType("files/".$fileName,$_FILES['addfile']["type"]));
} else {
$addFile = $h->br($h->color("file ".$fileName." not uploaded!","red"));
}
} else {
$addFile = "";
}
//~ priority to link
if (empty($_POST['link']) === false) {// if link exist
if ($h->url_exists($h->safe($_POST['link'])) === false){
return $h->h3($t->wr("link url not exist"),$h->v("style","color:red;"));
}
$_POST['type'] = "link";
} elseif (empty($_POST['type']) === false){//if new type exist
$_POST['link'] = "";
} else {// set type with scroll
$_POST['type'] = $_POST['set_type'];
$_POST['link'] = "";
}
if (empty($_POST['name'])){return $h->h3($t->wr("title empty !"));}
$name = strip_tags($_POST['name']);
//~ add to SANBOX (id2) if not parent
if ( !isset($_POST['parent']) ) {
$_POST['parent'] = 2;
}
$query = INSERTINTO.PAGES." (NAME,PARENTID,DESCRIPTION,PAGEHEAD,TYPEPAGE,LANG,LINK,SORTSTYLE,DATEPAGE,HIDE,USERID,PRIORITY) VALUES (".
"'".$h->safe($name)."',".
"'".$h->num($_POST['parent'])."',".
"'".$h->safe($addFile).$h->safe($_POST['content'])."',".
"'".$h->safe($_POST['head'])."',".
"'".$h->safe($_POST['type'])."',".
"'".$h->safe($_POST['lang'])."',".
"'".$h->safe($_POST['link'])."',".
"'".$h->num($_POST['sortstyle'])."',".
"'".$date."',".
$hide.",".$_SESSION['userid'].",".
"'".$h->num($_POST['priority'])."');";
$this->q($query);
$result = $h->h3($t->wz("page").$h->quot($name).$t->wl("created !"));
$result .= $h->ahref("admin.php?action=pages",$t->wr("return").$t->w("pages"),$h->v("class","linkbtn"));
$result .= SP.$t->wr("or").$h->ahref("admin.php?action=add_page",$t->wr("return").$t->w("add page"),$h->v("class","linkbtn"));
return $result;
}
}
?>