id = $prj->id;
$this->pkey = $prj->pkey;
$this->title = $prj->title;
$this->comment = $prj->comment;
$this->authorid = $prj->authorid;
$this->roles = $prj->roles;
$this->statuses = $prj->statuses;
$this->roleperm = $prj->roleperm;
$this->category = $prj->category;
$this->todotype = $prj->todotype;
$this->autoassign = $prj->autoassign;
$this->projecttype = $prj->projecttype;
$this->projectstatus = $prj->projectstatus;
$this->statuses= $prj->statuses;
$this->updated = $prj->updated;
$this->regdate = $prj->regdate;
$this->authorname = get_user_by('id', $this->authorid)->display_name;
}
}
public function init($common){
$this->common = $common;
include($this->common->skinPath . "/buttons.php");
include($this->common->skinPath . "/views.php");
$this->buttons = $buttons;
$this->views = $views;
$this->ajtodo_roles = new AJTODO_Role($this->common);
$this->ajtodo_roles->setRoles();
$this->ajtodo_alert = new AJTODO_Alert($this->common);
}
private function getCreateProjectForm($rolename){
}
public static function getProjectKeyById($pid){
global $wpdb;
$obj = $wpdb->get_row("select pkey from ".AJTODO_DB_PROJECT." where id = ".$pid);
return $obj ? $obj->pkey : "";
}
public function setProject(){
global $wpdb;
if($this->id){
$obj = $wpdb->get_row("select * from ".AJTODO_DB_PROJECT." where id = ".$this->id);
$this->pkey = $obj->pkey;
$this->title = $obj->title;
$this->comment = $obj->comment;
$this->projecttype = $obj->projecttype;
$this->authorid = $obj->authorid;
$this->statuses= $obj->roles ? json_decode($obj->statuses, true) : array();
$this->roles= $obj->roles ? json_decode($obj->roles, true) : array();
$this->roleperm = $obj->roleperm ? json_decode($obj->roleperm, true) : array();
$this->statuses= $obj->statuses ? json_decode($obj->statuses, true) : array();
$this->category = $obj->category ? json_decode($obj->category, true) : array();
$this->todotype = $obj->todotype ? json_decode($obj->todotype, true) : array();
$this->autoassign = $obj->autoassign;
$this->updated = $obj->updated;
$this->regdate = $obj->regdate;
$this->donedate = $obj->donedate;
$this->currentuserperms = AJTODO_User::getPerms($this);
$this->currentuserstatus = AJTODO_User::getStatusRole($this);
$this->setPlanPerms();
$this->setTodoPerms();
$this->setDocPerms();
$this->setPlan();
}
}
public static function getProject($pid){
global $wpdb;
if($pid){
return $wpdb->get_row("select * from ".AJTODO_DB_PROJECT." where id = ".$pid);
}
return "";
}
private function setPlan(){
global $table_prefix, $wpdb;
$sql = "select *, IF(ISNULL(donedate), startdate, donedate) as a1 ";
$sql .= " from ".AJTODO_DB_PLAN." where projectid = ".$this->id;
$sql .= " order by a1";
$this->plan = $wpdb->get_results($sql, ARRAY_A);
}
private function setPlanPerms(){
foreach($this->currentuserperms as $pem){
if(strstr($pem, "tp_plan_"))
$this->planperms[] = $pem;
}
}
private function setDocPerms(){
foreach($this->currentuserperms as $pem){
if(strstr($pem, "tp_doc_"))
$this->docperms[] = $pem;
}
}
private function setTodoPerms(){
foreach($this->currentuserperms as $pem){
if(strstr($pem, "tp_todo_"))
$this->todoperms[] = $pem;
}
}
public function hasPerm($perm){
return in_array($perm, $this->currentuserperms);
}
public function createForm(){
global $wpdb;
include(AJTODO_PLUGIN_PATH . "inc/ajtodo_js.php");
$retform = "";
if(current_user_can("ajtodo_project_private") || current_user_can("ajtodo_project_team_create")){
$retform .= $this->setProject();
$retform .= $this->getForm_PKey();
$retform .= $this->getForm_Title();
$retform .= $this->getForm_Projecttype();
$retform .= $this->getForm_AutoAssign();
$retform .= $this->getForm_Comment();
$retform = apply_filters('ajtodo_add_projectform_after', $retform);
$retform .= $this->getForm_Submits();
}else{
$retform .= $this->getForm_Error(__("권한이 없습니다.","ajtodo"));
}
$ret = "
";
return $ret;
}
private function getForm_PKey(){
$ret = "
";
return $ret;
}
private function getForm_Title(){
if(!$this->donedate){
$ret = "
";
}else{
$ret = "
";
}
return $ret;
}
private function getForm_Projecttype(){
$ret = "";
return $ret;
}
private function getForm_AutoAssign(){
$isY = true;
if($this->id){
$isY = $this->projecttype == "private";
}
$ret = "";
if(!$this->donedate){
$ret = "
";
}
return $ret;
}
private function getForm_Comment(){
if(!$this->donedate){
$ret = "
";
}else{
$ret = "
";
}
return $ret;
}
private function getForm_Submits(){
$ret = "";
if(!$this->donedate){
$ret .= "
";
if($this->id){
if( $this->projecttype == "private" ||
(current_user_can("ajtodo_project_team_close") && $this->projecttype == "team") ){
if($this->donedate){
$ret .= "
".__("프로젝트 활성화하기","ajtodo")."";
}else{
$ret .= "
".__("프로젝트 완료하기","ajtodo")."";
}
}
if( $this->projecttype == "private" ||
(current_user_can("ajtodo_project_team_remove") && $this->projecttype == "team") ){
$ret .= "
".__("프로젝트 삭제하기","ajtodo")."";
}
}
}else{
if( $this->projecttype == "private" ||
(current_user_can("ajtodo_project_team_close") && $this->projecttype == "team") ){
$ret .= "
".__("프로젝트 활성화하기","ajtodo")."";
}
if( $this->projecttype == "private" ||
(current_user_can("ajtodo_project_team_remove") && $this->projecttype == "team") ){
$ret .= "
".__("프로젝트 삭제하기","ajtodo")."";
}
}
$ret .= "
";
return $ret;
}
private function getForm_Error($msg){
return "";
}
private function valSet($val){
$val = $val == ":_NULL_:" ? "" : $val;
$val = $val == ":_NOW_:" ? date("Y-m-d H:i:s") : $val;
return $val;
}
public function updateCols($colval){
global $wpdb;
$user = wp_get_current_user();
$ar = array();
$sql = "update ".AJTODO_DB_PROJECT." set ";
foreach($colval as $key => $val){
$val = $this->valSet($val);
if($val){
array_push($ar, "$key = '$val' ");
}else{
array_push($ar, "$key = NULL ");
}
}
$sql .= implode(",", $ar);
$sql .= " where id = $this->id";
if($wpdb->query($sql) === FALSE){
do_action('ajtodo_modify_project', $this->id);
return false;
}else{
return true;
}
}
public function updateTodo($colval, $wherecol, $whereval){
global $wpdb;
$ar = array();
$sql = "update ".AJTODO_DB_TODO."_".$this->id." set ";
foreach($colval as $key => $val){
$val = $this->valSet($val);
if($val){
array_push($ar, "$key = '$val' ");
}else{
array_push($ar, "$key = NULL ");
}
}
$sql .= implode(",", $ar);
$sql .= " where 0 = 0 ";
if($wherecol && $whereval){
$sql .= " and ".$wherecol." = '".$whereval."'";
}
if($wpdb->query($sql) === FALSE){
do_action('ajtodo_modify_project', $this->id);
return false;
}else{
return true;
}
}
public function updateCol($col, $val){
global $table_prefix, $wpdb;
$sql = "update ".AJTODO_DB_PROJECT." set $col = '".esc_sql($val)."' where id = ".$this->id;
if($wpdb->query($sql) === FALSE){
do_action('ajtodo_modify_project', $this->id);
return false;
}else{
return true;
}
}
public function editProject(){
global $table_prefix, $wpdb;
$sql = "update ".AJTODO_DB_PROJECT." set
title = '".$this->title."',
autoassign = '".($this->autoassign ? "Y" : "N")."',
comment = '".$this->comment."',
updated = '".date("Y-m-d H:i:s")."' where id = $this->id";
$result = $wpdb->query($sql);
if($result){
do_action('ajtodo_modify_project', $this->id);
return true;
}else{
return false;
}
}
private function isUniqueKey($col, $val){
global $table_prefix, $wpdb;
$sql = "select count(id) from ".AJTODO_DB_PROJECT." where ".$col." = '".$val."'";
return $wpdb->get_var($sql) == 0;
}
private function createTodoTable($pid){
global $table_prefix, $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE ".AJTODO_DB_TODO."_".$pid." (
id int(11) NOT NULL AUTO_INCREMENT,
tkey varchar(100) NOT NULL,
projectid int(11) NOT NULL,
statuskey varchar(30) NOT NULL,
categorykey varchar(30) NULL,
planid int(11) NOT NULL DEFAULT 0,
authorid int(11) NOT NULL,
assignid int(11) NULL,
title varchar(255) NOT NULL,
comment longtext NOT NULL,
metadata longtext NULL,
todotype varchar(50) NULL,
regdate datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated datetime,
donedated datetime NULL,
PRIMARY KEY (id)
) $charset_collate;";
$wpdb->query($sql);
}
public function createProject(){
global $table_prefix, $wpdb;
$user = wp_get_current_user();
$isautoassign = "N";
if($this->projecttype == "private"){
$isautoassign = "Y";
}else{
$isautoassign = $this->autoassign ? "Y" : "N";
}
if(!$this->pkey){
$this->msg = __("프로젝트 키를 등록해주시기 바랍니다.","ajtodo");
return false;
}
if(!$this->isUniqueKey("pkey", $this->pkey)){
$this->msg = __("프로젝트 키가 중복됩니다. ","ajtodo");
return false;
}
$sql = "insert into ".AJTODO_DB_PROJECT."(
pkey,
title,
comment,
projecttype,
authorid,
autoassign,
projectstatus,
roleperm,
statuses,
roles,
todotype,
regdate) values(
'".$this->pkey."',
'".$this->title."',
'".$this->comment."',
'".$this->projecttype."',
".$user->ID.",
'".$isautoassign."',
'".AJTODO_PROJECT_STATUS_S."', ";
$sql .= "'".AJTODO_ProjectDefault::DefaultRolePerms()."', ";
$sql .= "'".AJTODO_ProjectDefault::DefaultStatus()."',
'".AJTODO_ProjectDefault::DefaultRoles($user->ID)."',
'".AJTODO_ProjectDefault::DefaultTodoType()."',
'".date("Y-m-d H:i:s")."'
)";
$result = $wpdb->query($sql);
if($result){
$this->id = $wpdb->insert_id;
$this->createTodoTable($this->id);
$wpdb->query("insert into ".AJTODO_DB_PROJECTKEYS." values($this->id, 0);");
do_action('ajtodo_add_project', $this->id);
return true;
}else{
$this->msg = __("프로젝트 생성중에 문제가 발생했습니다. ","ajtodo");
return false;
}
}
public function getNewTodoIndex(){
global $wpdb;
return $wpdb->get_var("select todonewindex + 1 from ".AJTODO_DB_PROJECTKEYS." where projectid = ".$this->id);
}
public function setNewTodoIndex($newid){
global $wpdb;
$wpdb->query("update ".AJTODO_DB_PROJECTKEYS." set todonewindex = $newid where projectid = ".$this->id);
}
public function delProject(){
global $wpdb;
$user = wp_get_current_user();
$wpdb->query("drop table ".AJTODO_DB_TODO."_".$this->id);
$wpdb->query("delete from ".AJTODO_DB_PLAN." where projectid = ".$this->id);
$wpdb->query("delete from ".AJTODO_DB_PROJECTKEYS." where projectid = ".$this->id);
$wpdb->query("delete from ".AJTODO_DB_PROJECT." where authorid = $user->ID and id = ".$this->id);
do_action('ajtodo_del_project', $this->id);
return true;
}
public function doneProject(){
global $table_prefix, $wpdb;
$status = AJTODO_ProjectStatus::getSingleStatusByStatus($this->statuses, "D");
$user = wp_get_current_user();
$time = date("Y-m-d H:i:s");
$wpdb->query("update ".AJTODO_DB_TODO."_".$this->id." set donedated = '$time', statuskey = '".$status["key"]."' where donedated is null");
$wpdb->query("update ".AJTODO_DB_PROJECT." set donedate = '$time' where authorid = $user->ID and id = ".$this->id);
do_action('ajtodo_done_project', $this->id);
return true;
}
public function activeProject(){
global $table_prefix, $wpdb;
$user = wp_get_current_user();
$time = date("Y-m-d H:i:s");
$wpdb->query("update ".AJTODO_DB_PROJECT." set donedate = NULL where authorid = $user->ID and id = ".$this->id);
do_action('ajtodo_active_project', $this->id);
return true;
}
public function getNoProjectCount(){
$this->percent = 0;
}
public function getCount(){
global $table_prefix, $wpdb;
$this->totalissue = $wpdb->get_var("select count(*) from ".AJTODO_DB_TODO."_".$this->id);
$this->doneissue = $wpdb->get_var("select count(*) from ".AJTODO_DB_TODO."_".$this->id." where donedated is not null");
$this->percent = 0;
if($this->totalissue){
$this->percent = round($this->doneissue * 100 / $this->totalissue, 0);
}
}
public function getDoneConfirmView(){
global $table_prefix, $wpdb;
if($this->id){
$this->getCount();
$user = wp_get_current_user();
$sql = "select * from ".AJTODO_DB_PROJECT." where
authorid = $user->ID and
id = ".$this->id;
$obj = $wpdb->get_row($sql);
$obj->totalissue = $this->totalissue;
$obj->doneissue = $this->doneissue;
$obj->percent = round($this->percent);
if($obj){
$data = ajtodo_T($obj, $this->views["ProjectDoneConfirm"]);
return ajtodo_T($this, $data);
}else{
return str_replace("[ALERT_MSG]", __("권한이 없습니다.","ajtodo"), $this->views["Alert"]);
}
}else{
return str_replace("[ALERT_MSG]", __("잘못된 접근입니다.","ajtodo"), $this->views["Alert"]);
}
}
public function getDelConfirmView(){
global $table_prefix, $wpdb;
if($this->id){
$this->getCount();
$user = wp_get_current_user();
$sql = "select * from ".AJTODO_DB_PROJECT." where
authorid = $user->ID and
id = ".$this->id;
$obj = $wpdb->get_row($sql);
$obj->totalissue = $this->totalissue;
$obj->doneissue = $this->doneissue;
if($obj){
$data = ajtodo_T($obj, $this->views["ProjectDelConfirm"]);
return ajtodo_T($this, $data);
}else{
return str_replace("[ALERT_MSG]", __("권한이 없습니다.","ajtodo"), $this->views["Alert"]);
}
}else{
return str_replace("[ALERT_MSG]", __("잘못된 접근입니다.","ajtodo"), $this->views["Alert"]);
}
}
public function getView(){
if($this->id){
$this->getCount();
$this->comment = nl2br($this->comment);
return $this->getCard();
}
}
public function showMemberList(){
$ret = "";
$arrusers = is_array($this->roles) ? $this->roles : json_decode($this->roles, true);
foreach(AJTODO_User::getUsersByRoles($arrusers) as $user){
$ret .= "";
$ret .= str_replace("
$this->pkey |
$this->title |
|
$this->doneissue/$this->totalissue |
".$this->showMemberList()." | ";
$ret .="";
return $ret;
}
public function getButton($rolename){
if($this->ajtodo_roles->roles[$rolename]){
return $this->buttons[$rolename];
}else{
return "";
}
}
private function getUserInfo($uid){
$arrusers = is_array($this->roles) ? $this->roles : json_decode($this->roles, true);
foreach(AJTODO_User::getUsersByRoles($arrusers) as $user){
if($user["id"] == $uid)
return $user;
}
return null;
}
public function getDailyRemainIssues($planid = ""){
global $wpdb;
$labels = array();
$datasets = array();
if($planid){
$pl = new AJTODO_ProjectPlan();
$planInfo = $pl->getPlan($planid);
$begin = new DateTime(substr($planInfo->startdate, 0, 10));
$end = new DateTime(substr($planInfo->finishdate, 0, 10));
for($i = $begin; $i <= $end; $i->modify('+1 day')){
$labels[] = $i->format("m/d");
}
$sql = "select DATE(donedated) as x, count(*) as y from ".AJTODO_DB_TODO."_".$this->id;
$sql .= " where donedated is not null ";
if($planid)
$sql .= " and planid = ".$planid;
$sql .= " group by x";
$list = $wpdb->get_results($sql);
$data = array();
$bg = array();
$bd = array();
foreach($labels as $label){
$setval = false;
foreach($list as $item){
$newx = new DateTime($item->x);
if($label == $newx->format("m/d")){
$data[] = $item->y;
$setval = true;
break;
}
}
if(!$setval)
$data[] = 0;
$bg[] = "rgba(54, 162, 235, 0.2)";
$bd[] = "rgba(54, 162, 235, 1)";
}
$datasets[] = array(
"data" => $data,
"backgroundColor" => $bg,
"borderColor" => $bd,
"borderWidth" => 1
);
}
return array("labels" => $labels, "datasets" => $datasets);
}
public function getPlanSelector($planid = ""){
global $wpdb;
$nowplaninfo = "";
if($planid){
foreach($this->plan as $p){
if($planid == $p["id"]){
$nowplaninfo = $p;
break;
}
}
}
$link = "?page=ajtodo_admin_project&ptype=team&ajtodo_type=report&pid=".$this->id;
$ret = "
";
$ret .= "";
$ret .= "";
$ret .= "
";
return $ret;
}
public function quickLink($planid = ""){
$link = "?page=ajtodo_admin_project&ptype=team&ajtodo_type=plan&pid=".$this->id;
if($planid)
$link .= "&plankey=".$planid;
$ret = "
";
return $ret;
}
public function getLinkedDocs($planid = ""){
global $wpdb;
$adddoclink = "/wp-admin/post-new.php?post_type=ajtododoc&pid=".$this->id;
if($planid)
$adddoclink .= "&planid=".$planid;
$ret = "
";
$ret .= "
";
$ret .= "";
$ret .= "
";
$ttype = new AJTODO_ProjectLink();
$ttype->project = $this;
$list = $planid ? $ttype->getLinkedDocsByPlan($planid) : $ttype->getLinkedDocsByProject();
if(!count($list)){
$ret .= "
";
$ret .= __("문서 없음", "ajtodo");
$ret .= "
";
}else{
$ret .= "
";
foreach($list as $item){
$post = get_post($item->postid);
$ret .= " - ";
$ret .= str_replace("
post_author, 24));
$ret .= " ";
$ret .= " ".$post->post_title."";
$ret .= "";
$ret .= " ".date("m/d H:i:s", strtotime($post->post_modified))."";
$ret .= " ";
}
$ret .= "
";
}
$ret .= "
";
$ret .= "
";
$ret .= "
";
return $ret;
}
public function getReportIssueByTodoType($planid = ""){
global $wpdb;
$ret = "
";
$ret .= "
";
$ret .= "";
$ret .= "
";
$ttype = new AJTODO_ProjectTodoType();
$ttype->project = $this;
$totaltodo = $wpdb->get_var("select count(id) from ".AJTODO_DB_TODO."_".$this->id.($planid ? " where planid = $planid " : ""));
$sql = "SELECT todotype, count(*) as cnt FROM ".AJTODO_DB_TODO."_".$this->id;
if($planid)
$sql .= " where planid = ". $planid;
$sql .= " group by todotype";
$list = $wpdb->get_results($sql);
$ret .= "
";
foreach($list as $item){
$t = $ttype->getSingleTodoType($item->todotype);
$per = $item->cnt * 100 / $totaltodo;
$ret .= " ";
$ret .= " | ";
$ret .= " ".$t["name"]." ";
$ret .= " | ";
$ret .= " ";
$ret .= "".$item->cnt." ";
$ret .= " | ";
$ret .= "
";
}
$ret .= "
";
$ret .= "
";
$ret .= "
";
$ret .= "
";
return $ret;
}
public function getReportIssueByCategory($planid = ""){
global $wpdb;
$ret = "
";
$ret .= "
";
$ret .= "";
$ret .= "
";
$ttype = new AJTODO_ProjectCategory();
$ttype->project = $this;
$totaltodo = $wpdb->get_var("select count(id) from ".AJTODO_DB_TODO."_".$this->id.($planid ? " where planid = $planid " : ""));
$sql = "SELECT categorykey, count(*) as cnt FROM ".AJTODO_DB_TODO."_".$this->id;
if($planid)
$sql .= " where planid = ". $planid;
$sql .= " group by categorykey";
$list = $wpdb->get_results($sql);
$ret .= "
";
foreach($list as $item){
$c = $ttype->getSingleCategory($item->categorykey);
$per = $item->cnt * 100 / $totaltodo;
$ret .= " ";
$ret .= " | ";
if($c){
$ret .= " ".$c["name"]." ";
}else{
$ret .= "".__("카테고리 없음","ajtodo")." ";
}
$ret .= " | ";
$ret .= " ";
$ret .= "".$item->cnt." ";
$ret .= " | ";
$ret .= "
";
}
$ret .= "
";
$ret .= "
";
$ret .= "
";
$ret .= "
";
return $ret;
}
public function getReportIssueByUsers($planid = ""){
global $wpdb;
$ret = "
";
$ret .= "
";
$ret .= "";
$ret .= "
";
$totaltodo = $wpdb->get_var("select count(id) from ".AJTODO_DB_TODO."_".$this->id.($planid ? " where planid = $planid " : ""));
$sql = "SELECT assignid, count(*) as cnt FROM ".AJTODO_DB_TODO."_".$this->id;
if($planid)
$sql .= " where planid = $planid ";
$sql .= " group by assignid";
$assignlist = $wpdb->get_results($sql);
$ret .= "
";
foreach($assignlist as $item){
$u = $this->getUserInfo($item->assignid);
$per = $item->cnt * 100 / $totaltodo;
$ret .= " ";
$ret .= " ";
if($u){
$ret .= str_replace(" ";
}
$ret .= " | ";
$ret .= " ";
$ret .= "".$item->cnt." ";
$ret .= " | ";
$ret .= "
";
}
$ret .= "
";
$ret .= "
";
$ret .= "
";
$ret .= "
";
return $ret;
}
public function getDailRemainChart($planid = ""){
$ret = "
";
$ret .= "
";
$ret .= "";
$ret .= "
";
$ret .= " ";
$ret .= "
";
$ret .= "
";
$ret .= "
";
return $ret;
}
public function getReportSummary($planid = "", $freez = false){
$nowplaninfo = "";
if($planid){
foreach($this->plan as $p){
if($planid == $p["id"]){
$nowplaninfo = $p;
break;
}
}
}
$ret = "
";
$ret .= "
";
$ret .= "";
$ret .= "
";
if($nowplaninfo){
$ret .= "
".$nowplaninfo["plancomment"]."
";
$ret .= "
".__("시작일")." : ".substr($nowplaninfo["startdate"],0, 10);
if($nowplaninfo["donedate"]){
$ret .= " ~ ".__("완료일")." : ".substr($nowplaninfo["donedate"],0, 10)." (".__("목표일")." : ".substr($nowplaninfo["finishdate"],0, 10).")";
}else{
$ret .= " ~ ".__("목표일")." : ".substr($nowplaninfo["finishdate"],0, 10);
}
$ret .= "
";
if(!$nowplaninfo["donedate"]){
$ret .= " ".$this->getPlanProgress2($nowplaninfo["id"])."";
}
}else{
$ret .= "
".nl2br($this->comment)."
";
}
$ret .= "
";
$ret .= $this->showMemberList();
$ret .= "
";
$ret .= "
";
$ret .= "
";
$ret .= "
";
return $ret;
}
public function getPlanProgress2($plankey){
global $wpdb;
$ret = array();
$sql = "SELECT statuskey, count(*) as cnt FROM ".AJTODO_DB_TODO."_".$this->id." where planid = ".$plankey;
$sql .= " group by statuskey";
$statuslist = $wpdb->get_results($sql, ARRAY_A);
$closed = 0;
$open = 0;
$ing = 0;
$all = 0;
foreach($statuslist as $status){
if($status['statuskey'] == "closed"){
$closed += $status['cnt'];
}else if($status['statuskey'] == "open"){
$open += $status['cnt'];
}else{
$ing += $status['cnt'];
}
$all += $status['cnt'];
}
$perc_o = 0; $perc_i = 0;
if($all > 0){
$perc_o = round(($closed * 100) / $all);
$perc_i = round(($ing * 100) / $all);
}
$ret = "