<commit_before><?
require_once("bootstrap.inc.php");
require_once("include_pouet/box-modalmessage.php");
require_once("include_pouet/box-prod-submit.php");

if ($currentUser && !$currentUser->CanEditItems())
{
  redirect("prod.php?which=".(int)$_GET["which"]);
  exit();
}

///////////////////////////////////////////////////////////////////////////////

class PouetBoxAdminEditProd extends PouetBoxSubmitProd
{
  function PouetBoxAdminEditProd( $id )
  {
    parent::__construct();

    $this->id = (int)$id;

    $this->prod = PouetProd::Spawn( $this->id );
    if (!$this->prod) return;
    $a = array(&$this->prod);
    PouetCollectPlatforms( $a );

    $this->title = "edit this prod: ".$this->prod->RenderLink();
  }
  use PouetForm;
  function Commit($data)
  {
    //die("almost there");
    $a = array();
    $a["name"] = $data["name"];
    $a["download"] = $data["download"];

    if ($data["releaseDate_month"] && $data["releaseDate_year"] && checkdate( (int)$data["releaseDate_month"], 15, (int)$data["releaseDate_year"]) )
      $a["releaseDate"] = sprintf("%04d-%02d-15",$data["releaseDate_year"],$data["releaseDate_month"]);
    else if ($data["releaseDate_year"])
      $a["releaseDate"] = sprintf("%04d-00-15",$data["releaseDate_year"]);
    else
      $a["releaseDate"] = null;

    $a["type"] = implode(",",$data["type"]);

    $groups = array();
    if ($data["group1"]) $groups[] = (int)$data["group1"];
    if ($data["group2"]) $groups[] = (int)$data["group2"];
    if ($data["group3"]) $groups[] = (int)$data["group3"];
    $groups = array_unique($groups);
    if (count($groups)) $a["group1"] = array_shift($groups); else $a["group1"] = null;
    if (count($groups)) $a["group2"] = array_shift($groups); else $a["group2"] = null;
    if (count($groups)) $a["group3"] = array_shift($groups); else $a["group3"] = null;

    $a["csdb"] = $data["csdbID"];
    $a["sceneorg"] = $data["sceneOrgID"];
    //$a["zxdemo"] = $data["zxdemoID"];
    $a["demozoo"] = $data["demozooID"];
    $a["party"] = nullify($data["partyID"]);
    $a["party_year"] = $data["partyYear"];
    $a["party_compo"] = nullify($data["partyCompo"]);
    $a["party_place"] = $data["partyRank"];
    $a["invitation"] = nullify($data["invitationParty"]);
    $a["invitationyear"] = $data["invitationYear"];
    $a["boardID"] = nullify($data["boardID"]);
    global $prodID;
    SQLLib::UpdateRow("prods",$a,"id=".(int)$this->id);

    $data["platform"] = array_unique($data["platform"]);
    SQLLib::Query(sprintf_esc("delete from prods_platforms where prod = %d",(int)$this->id));
    foreach($data["platform"] as $v)
    {
      $a = array();
      $a["prod"] = (int)$this->id;
      $a["platform"] = $v;
      SQLLib::InsertRow("prods_platforms",$a);
    }

    if(is_uploaded_file($_FILES["screenshot"]["tmp_name"]))
    {
      foreach( array( "jpg","gif","png" ) as $v )
        @unlink( get_local_screenshot_path( (int)$this->id, $v ) );

      list($width,$height,$type) = GetImageSize($_FILES["screenshot"]["tmp_name"]);
      $extension = "_";
      switch($type) {
        case 1:$extension="gif";break;
        case 2:$extension="jpg";break;
        case 3:$extension="png";break;
      }
      if ($extension != "_")
        move_uploaded_file_fake( $_FILES["screenshot"]["tmp_name"], get_local_screenshot_path( (int)$this->id, $extension ) );
    }
    if(is_uploaded_file($_FILES["nfofile"]["tmp_name"]))
    {
      move_uploaded_file_fake( $_FILES["nfofile"]["tmp_name"], get_local_nfo_path( (int)$this->id ) );
    }

    gloperator_log( "prod", (int)$this->id, "prod_edit" );

    return array();
  }
  function LoadFromDB()
  {
    parent::LoadFromDB();

    $prod = $this->prod;

    $a = array();
    $this->fields["name"]["value"] = $prod->name;
    $this->fields["download"]["value"] = $prod->download;

    $n = 1;
    foreach($prod->groups as $g)
      $this->fields["group".$n++]["value"] = $g->id;

    $this->fields["releaseDate"]["value"] = $prod->releaseDate;

    $this->fields["platform"]["value"] = array_keys($prod->platforms);
    $this->fields["type"]["value"] = $prod->types;

    if (count($prod->placings) > 0)
    {<commit_msg>flush link check state if prod is changed<commit_after><?
require_once("bootstrap.inc.php");
require_once("include_pouet/box-modalmessage.php");
require_once("include_pouet/box-prod-submit.php");

if ($currentUser && !$currentUser->CanEditItems())
{
  redirect("prod.php?which=".(int)$_GET["which"]);
  exit();
}

///////////////////////////////////////////////////////////////////////////////

class PouetBoxAdminEditProd extends PouetBoxSubmitProd
{
  function PouetBoxAdminEditProd( $id )
  {
    parent::__construct();

    $this->id = (int)$id;

    $this->prod = PouetProd::Spawn( $this->id );
    if (!$this->prod) return;
    $a = array(&$this->prod);
    PouetCollectPlatforms( $a );

    $this->title = "edit this prod: ".$this->prod->RenderLink();
  }
  use PouetForm;
  function Commit($data)
  {
    //die("almost there");
    $a = array();
    $a["name"] = $data["name"];
    $a["download"] = $data["download"];

    if ($data["releaseDate_month"] && $data["releaseDate_year"] && checkdate( (int)$data["releaseDate_month"], 15, (int)$data["releaseDate_year"]) )
      $a["releaseDate"] = sprintf("%04d-%02d-15",$data["releaseDate_year"],$data["releaseDate_month"]);
    else if ($data["releaseDate_year"])
      $a["releaseDate"] = sprintf("%04d-00-15",$data["releaseDate_year"]);
    else
      $a["releaseDate"] = null;

    $a["type"] = implode(",",$data["type"]);

    $groups = array();
    if ($data["group1"]) $groups[] = (int)$data["group1"];
    if ($data["group2"]) $groups[] = (int)$data["group2"];
    if ($data["group3"]) $groups[] = (int)$data["group3"];
    $groups = array_unique($groups);
    if (count($groups)) $a["group1"] = array_shift($groups); else $a["group1"] = null;
    if (count($groups)) $a["group2"] = array_shift($groups); else $a["group2"] = null;
    if (count($groups)) $a["group3"] = array_shift($groups); else $a["group3"] = null;

    $a["csdb"] = $data["csdbID"];
    $a["sceneorg"] = $data["sceneOrgID"];
    //$a["zxdemo"] = $data["zxdemoID"];
    $a["demozoo"] = $data["demozooID"];
    $a["party"] = nullify($data["partyID"]);
    $a["party_year"] = $data["partyYear"];
    $a["party_compo"] = nullify($data["partyCompo"]);
    $a["party_place"] = $data["partyRank"];
    $a["invitation"] = nullify($data["invitationParty"]);
    $a["invitationyear"] = $data["invitationYear"];
    $a["boardID"] = nullify($data["boardID"]);
    global $prodID;
    SQLLib::UpdateRow("prods",$a,"id=".(int)$this->id);

    $data["platform"] = array_unique($data["platform"]);
    SQLLib::Query(sprintf_esc("delete from prods_platforms where prod = %d",(int)$this->id));
    foreach($data["platform"] as $v)
    {
      $a = array();
      $a["prod"] = (int)$this->id;
      $a["platform"] = $v;
      SQLLib::InsertRow("prods_platforms",$a);
    }

    if(is_uploaded_file($_FILES["screenshot"]["tmp_name"]))
    {
      foreach( array( "jpg","gif","png" ) as $v )
        @unlink( get_local_screenshot_path( (int)$this->id, $v ) );

      list($width,$height,$type) = GetImageSize($_FILES["screenshot"]["tmp_name"]);
      $extension = "_";
      switch($type) {
        case 1:$extension="gif";break;
        case 2:$extension="jpg";break;
        case 3:$extension="png";break;
      }
      if ($extension != "_")
        move_uploaded_file_fake( $_FILES["screenshot"]["tmp_name"], get_local_screenshot_path( (int)$this->id, $extension ) );
    }
    if(is_uploaded_file($_FILES["nfofile"]["tmp_name"]))
    {
      move_uploaded_file_fake( $_FILES["nfofile"]["tmp_name"], get_local_nfo_path( (int)$this->id ) );
    }

    gloperator_log( "prod", (int)$this->id, "prod_edit" );
    
    SQLLib::Query(sprintf_esc("delete from prods_linkcheck where prodID = %d",$this->id));

    return array();
  }
  function LoadFromDB()
  {
    parent::LoadFromDB();

    $prod = $this->prod;

    $a = array();
    $this->fields["name"]["value"] = $prod->name;
    $this->fields["download"]["value"] = $prod->download;

    $n = 1;
    foreach($prod->groups as $g)
      $this->fields["group".$n++]["value"] = $g->id;

    $this->fields["releaseDate"]["value"] = $prod->releaseDate;

    $this->fields["platform"]["value"] = array_keys($prod->platforms);
    $this->fields["type"]["value"] = $prod->types;

    if (count($prod->placings) > 0)
    {
{'fraction_non_alphanumeric': 0.2498221484467631, 'fraction_numerical': 0.007351197533791795, 'mean_word_length': 3.9183673469387754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3262421', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2991, 'n_words': 433}