Skip to content

Commit

Permalink
add cdc editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargaj committed Dec 30, 2021
1 parent 94812c6 commit a5ea176
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 2 deletions.
1 change: 1 addition & 0 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function Render()
{
echo " <li><a href='admin_compotypes_edit.php'>edit compo types</a></li>";
echo " <li><a href='admin_faq.php'>edit faq items</a></li>";
echo " <li><a href='admin_cdc.php'>edit cdcs</a></li>";
}
echo "</ul>\n";
echo "</div>\n";
Expand Down
175 changes: 175 additions & 0 deletions admin_cdc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php
require_once("bootstrap.inc.php");
require_once("include_pouet/box-modalmessage.php");
require_once("include_pouet/box-party-submit.php");
require_once("include_pouet/pouet-box-editbase.php");

if ($currentUser && !$currentUser->IsModerator())
{
redirect("index.php");
exit();
}

class PouetBoxAdminAddCDC extends PouetBoxEditConnectionsBase
{
public static $slug = "CDC";
function __construct( )
{
parent::__construct();
$this->uniqueID = "pouetbox_admineditcdc";
$this->title = "edit cdcs";
$this->headers = array("prod","groups","added date");

$s = new BM_Query();
$s->AddTable("cdc");
$s->AddField("cdc.id");
$s->AddField("cdc.addedDate");
$s->attach(array("cdc"=>"which"),array("prods as prod"=>"id"));
$s->AddOrder("cdc.addedDate");
$this->data = $s->perform();

$a = array();
foreach($this->data as $v) $a[] = &$v->prod;
PouetCollectPlatforms($a);
}
use PouetForm;
function Commit($data)
{
if ($data["delAffil"])
{
SQLLib::Query("delete from cdc where id=".(int)$data["delCDC"]);
return array();
}

$a = array();
$a["which"] = $data["which"];
$a["addedDate"] = $data["addedDate"];
if ($data["editCDCID"])
{
SQLLib::UpdateRow("cdc",$a,"id=".(int)$data["editCDCID"]);
$a["id"] = $data["editCDCID"];
}
else
{
$a["id"] = SQLLib::InsertRow("cdc",$a);
}

@unlink(POUET_ROOT_LOCAL . 'cache/pouetbox_cdc.cache' );

if ($data["partial"])
{
$o = toObject($a);
$o->prod = PouetProd::Spawn($a["which"]);
$this->RenderNormalRow($o);
$this->RenderNormalRowEnd($o);
exit();
}

return array();
}
function RenderEditRow($row)
{
echo " <td colspan='2'><input name='which' value='"._html( $row->prod->id )."' class='prodID'/></td>\n";
echo " <td><input name='addedDate' value='"._html( $row->addedDate ? $row->addedDate : date("Y-m-d") )."'/></td>\n";
}
function RenderNormalRow($v)
{
echo "<td>\n";
echo $v->prod->RenderTypeIcons();
echo $v->prod->RenderPlatformIcons();
echo "<span class='prod'>".$v->prod->RenderLink()."</span>\n";
echo "</td>\n";

echo "<td>\n";
echo $v->prod->RenderGroupsShortProdlist();
echo "</td>\n";

echo "<td>\n";
echo $v->addedDate;
echo "</td>\n";
}
function RenderBody()
{
parent::RenderBody();
?>
<script>
<!--
document.observe("dom:loaded",function(){
InstrumentAdminEditorForAjax( $("pouetbox_admineditcdc"), "prodAffil", {
onRowLoad: function(tr){
new Autocompleter(tr.down(".prodID"), {
"dataUrl":"./ajax_prods.php",
"processRow": function(item) {
var s = item.name.escapeHTML();
if (item.groupName) s += " <small class='group'>" + item.groupName.escapeHTML() + "</small>";
return s;
}
});
}
} );
});
//-->
</script>
<?php
}
}


$boxen = array(
"PouetBoxAdminAddCDC",
);
if($_GET["partial"] && $currentUser && $currentUser->CanEditItems())
{
// ajax responses
$prod = new stdClass();
$prod->id = $_GET["which"];
foreach($boxen as $class)
{
if ($_GET["edit" . $class::$slug])
{
$box = new $class( $prod );
$box->RenderEditRow( $box->GetRow( $_GET["edit" . $class::$slug] ) );
$box->RenderEditRowEnd( $box->GetRow( $_GET["edit" . $class::$slug] ) );
}
if ($_GET["new" . $class::$slug])
{
$box = new $class( $prod );
$box->RenderEditRow( new stdClass() );
$box->RenderEditRowEnd( new stdClass() );
}
}
exit();
}

$form = new PouetFormProcessor();

$form->SetSuccessURL( "admin_cdc.php", true );

$form->Add( "prod", new PouetBoxAdminAddCDC() );
if ($currentUser && $currentUser->CanEditItems())
$form->Process();

$TITLE = "edit faq";

require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");

echo "<div id='content'>\n";

if (get_login_id())
{
$form->Display();
}
else
{
require_once("include_pouet/box-login.php");
$box = new PouetBoxLogin();
$box->Render();
}

echo "</div>\n";

require("include_pouet/menu.inc.php");
require_once("include_pouet/footer.php");

?>
2 changes: 0 additions & 2 deletions cdc.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ function RenderBody()
{
echo "\n\n";
echo "<table class='boxtable'>\n";
$lastYear = 0;
$lastCategory = "";
foreach ($this->cdcs as $row)
{
$p = $row->prod;
Expand Down

0 comments on commit a5ea176

Please sign in to comment.