{
  "pluginname": "Online Author",
  "systemplugin": "0",
  "version": "1.4",
  "table_def": [
    {
      "name": "online_author",
      "fields": [
        {
          "name": "authorname",
          "type": "varchar(50)",
          "other": "NOT NULL"
        },
        {
          "name": "description",
          "type": "varchar(500)",
          "other": "NOT NULL"
        },
        {
          "name": "image_path",
          "type": "varchar(300)"
        },{
          "name": "linked_to_institution",
          "type": "varchar(10)"
        },
        {
          "name": "status",
          "type": "tinyint",
          "other": "NOT NULL DEFAULT 1"
        },
        {
          "name": "owner",
          "type": "uniqueidentifier"
        }
      ]
    }
  ],
  "sqlcommands_oninstall": [],
  "form": {
    "name": "online_author",
    "formtype": "Default",
    "title": "Online Course Author",
    "icon": "mif-user fg-white",
    "saveButton": "true",
    "savecustomid":6,
	"getrecordcustomid":7,
    "cancelButton": "true",
    "flex_row": "false",
    "flex_justify": "start",
    "width": "400px",
    "field": [
      {
        "name": "authorname",
        "label": "Author Name",
        "fieldtype": "s",
        "type": "text",
        "required": "Yes",
		"maxlength":"50"
      },
      {
        "name": "description",
        "label": "Description",
        "fieldtype": "s",
        "type": "textarea",
        "required": "Yes",
		"maxlength":"500"
      },{
        "name": "linked_to_institution",
        "label": "Institution",
        "fieldtype": "s",
        "type": "select",
		"option":"Select,NIBS,NBBI,NIBI,Other",
        "required": "Yes"
      },{
        "name": "image_path",
        "label": "Image Path",
        "fieldtype": "s",
        "type": "file",
        "required": "Yes",
		"maxlength":"300",
		"uploadstmt":"5"
      },{
        "name": "owner",
        "label": "Owner",
        "fieldtype": "u",
        "type": "select",
        "required": "Yes",
		"option":"SELECT id,fullname FROM online_course_users WHERE isfaculty=1 and status=1"
      }
    ]
  },
  "form_html": "",
  "navbutton": [
    {
      "customid": "1",
      "caption": "Author",
      "icon": "mif-user fg-steel",
      "btntype": "ribbon-button",
      "btngroup": "Online Course",
      "btntab": "Online Education",
      "btnorder": "2",
      "onclick": "initializePlugin()"
    }
  ],
  "script": "",
  "formbuttons": [
    {
      "name": "addAuthor",
      "icon": "mif-plus fg-red",
      "onclick": "showNewForm('online_author')"
    },
    {
      "name": "activeAuthor",
      "caption": "Active Author",
      "icon": "mif-user fg-green",
      "onclick": "getTableFromSqlStatement('1')"
    },
    {
      "name": "inactiveAuthor",
      "caption": "Inactive Author",
      "icon": "mif-user fg-orange",
      "onclick": "getTableFromSqlStatement('2')"
    },
    {
      "name": "deletedAuthor",
      "caption": "Deleted Author",
      "icon": "mif-user fg-red",
      "onclick": "getTableFromSqlStatement('3')"
    }
  ],
  "sqlstatement": [
    {
      "customid": "1",
      "name": "activeAuthor",
      "sql": {"action":"Get Table","formname":"online_author","fld":"a.authorname,a.linked_to_institution","tbl":"online_author a","join":"LEFT JOIN online_course b ON b.authorid=a.id","whr":"a.status=1 and b.status=1","grp":"a.authorname,a.linked_to_institution","srt":"a.authorname","button":[{"name":"Active","sqlid":"1","whr":"a.status=1"},{"name":"Inactive","sqlid":"1","whr":"a.status=0 and b.status=1"},{"name":"Deleted","sqlid":"1","whr":"a.recordstatus=0 and b.status=1"}]},  	  
      "header": "Author Name,Institute",
      "filter": "1",
	  "filter_fields": "a.linked_to_institution",
      "filter_fields_operator": "=",
      "filter_fields_caption": "Select Institute",
      "filter_fields_type": "s",
      "filter_fields_inputtype": "select",
      "filter_fields_option": [{"fieldname":"a.linked_to_institution","option":"SELECT DISTINCT linked_to_institution FROM online_author WHERE status=1"}],
      "edit_record": "1",
      "delete_record": "1",
      "restore_record": "1",
	  "set_appendix":"4:AUTHORID:a.id:count(*):Course Count",
	  "function1":"changeRecordValue:a.id,'online_author','status','1','n':Activate Author",
	  "function2":"changeRecordValue:a.id,'online_author','status','0','n':Suspend Author"
    },
    {
      "customid": "2",
      "name": "inactiveAuthor",
      "sql": {"action":"Get Table","fld":"authorname","tbl":"online_author","whr":"status=0"},
	  "header": "Author Name",
      "filter": "0",
      "edit_record": "0",
      "delete_record": "1",
      "restore_record": "0",
      "change_status": "1:Activate Author:Author Activated:Author Activation Failed"
    },
    {
      "customid": "3",
      "name": "deletedAuthor",
      "sql": {"action":"Get Table","fld":"authorname","tbl":"online_author","whr":"recordstatus=0"},
	  "header": "Author Name",
      "filter": "0",
      "edit_record": "0",
      "delete_record": "0",
      "restore_record": "1"
    },{
	  "customid": "4",
      "name": "authorcourselist",
      "sql": {"action":"Get Table","param":"AUTHORID","fld":"a.title,a.price,a.department,a.programlinked,a.credit,a.timeneeded,count(*)","tbl":"online_course a","join":"LEFT JOIN online_lesson b ON b.courseid=a.id","whr":"a.status=1 and b.status=1 and a.authorid='||AUTHORID||'","grp":"a.title,a.price,a.department,a.programlinked,a.credit,a.timeneeded"},
	  "header": "Title,Price,Department,Program Linked,Credit,Timeneeded,Lesson Count",
      "filter": "0"
	},{
		"customid":"5",
		"name":"uploadAuthorImage",
		"sql":{"action":"Upload File","outputto":"html","output":"upload","param":"elemname","directory":"","maxsize":"100kb","filetype":"jpg,jpeg,png","path":"resource/media/","onsuccess":"cmd:dom,fun:showtoast Upload Successful-cmd:dom,elem:input[name=||elemname||],fun:val,val:||GET_uploadedfilename||","onfailure":"cmd:dom,fun:showtoast Upload Failed"}
	},{
		"customid":"6",
		"name":"saveAuthor",
		"sql":{"action":"Save Table","validate":"users","outputto":"html","output":"res","command":"insertorupdate","tbl":"online_author","fld":"authorname,description,linked_to_institution,image_path,owner","fldtype":"s,s,s,s,u","value":"||authorname||,||description||,||linked_to_institution||,||image_path||,||owner||","whr":"id='||ID||'","param":"authorname,description,linked_to_institution,image_path,owner,ID","successmsg":"Saving Successful","failuremsg":"Saving Failed"}
	},{
		"customid":"7",
		"name":"getRecord",
		"sql":{"action":"Get Row","validate":"users","outputto":"html","output":"edit","param":"ID","tbl":"online_author","fld":"id,authorname,description,linked_to_institution,image_path,owner","whr":"id='||ID||'"}
	}
  ]
}