PageRenderTime 14ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/controllers/CompanySettingManageCompany.cfc

http://raihan.googlecode.com/
ColdFusion CFScript | 180 lines | 120 code | 60 blank | 0 comment | 8 complexity | 3eaa28e04cf346359aaf8a7290afc83e MD5 | raw file
  1<cfcomponent displayname="Company Setting Manage Company" hint="Company Setting Manage Company" extends="Controller" output="false">
  2
  3	<cffunction name="init" access="public" hint="init" description="init">
  4		
  5		<cfscript>
  6			
  7			filters(through="isLoggedIn");
  8			
  9			flashInsert(menu="Company &gt; Setting &gt; Manage Company");
 10			
 11			provides("html,json");
 12			
 13			return this;
 14			
 15		</cfscript>
 16		
 17	</cffunction>
 18	
 19	<cffunction name="home" access="public" hint="home" description="home">
 20		
 21		<cfscript>
 22			
 23			company = model("company").findAll(select="id,companyname,address,phone,fax");
 24			
 25		</cfscript>
 26		
 27	</cffunction>
 28	
 29	<cffunction name="companyList" access="public" hint="company list" description="company list">
 30		<cfsetting showdebugoutput="false" enablecfoutputonly="true" >
 31		
 32		<cfscript>
 33			if (Len(Trim(decryptHex(form.qtype))) and Len(Trim(decryptHex(form.query)))) {
 34				companies = model("company").findAll(
 35					select="id,companyname,address,phone,fax", 
 36					where="#decryptHext(form.qtype)# = '#decryptHex(form.query)#'", 
 37					order="#decryptHex(form.sortname)# #form.sortorder#"
 38				);
 39			}
 40			else {
 41				companies = model("company").findAll(
 42					select="id,companyname,address,phone,fax", 
 43					order="#decryptHex(form.sortname)# #form.sortorder#"
 44				);
 45			}
 46			
 47			grid = flexigridstruct(query="#companies#", columns="companyname,address,phone,fax", page="#form.page#", rows="#form.rp#", key="id");
 48			
 49			renderWith(grid);
 50		</cfscript>		
 51		
 52	</cffunction> 
 53	
 54	<cffunction name="addCompany" access="public" hint="add company" description="add company">
 55				
 56	</cffunction> 
 57	
 58	<cffunction name="create" access="public" hint="create" description="create">
 59		
 60		<cfscript>
 61			
 62			if (not Len(Trim(params.company))) {
 63				flashInsert(error="Required : Company");
 64				redirectTo(action="home");
 65			}
 66			
 67			local.company = model("company").new();
 68			
 69			local.company.companyName = params.company;
 70			local.company.address = params.address;
 71			local.company.phone = params.phone;
 72			local.company.fax = params.fax;
 73			
 74			local.company.save();
 75			
 76			flashInsert(info="Successfully add company");
 77			redirectTo(action="home");
 78			
 79		</cfscript>
 80		
 81	</cffunction>
 82	
 83	<cffunction name="editCompany" access="public" hint="edit company" description="edit company">
 84		
 85		<cfscript>
 86			
 87			if (not StructKeyExists(params, "id")) {
 88				flashInsert(error="Failed load edit page");
 89				redirectTo(action="home");
 90			}
 91			
 92			local.id = Right(params.id, Len(params.id) - 3);
 93			
 94			try {
 95				local.id = decryptHex(local.id);
 96			}
 97			catch(Any e) {
 98				flashInsert(error="Failed load edit page");
 99				redirectTo(action="home");
100			}
101			
102			if (not IsNumeric(local.id)) {
103				flashInsert(error="Failed load edit page");
104				redirectTo(action="home");
105			}
106			
107			company = model("company").findAll(where="id = #local.id#");
108			
109			
110		</cfscript>
111		
112	</cffunction> 
113	
114	<cffunction name="update" access="public" hint="create" description="create">
115		
116		<cfscript>
117			
118			if (not Len(Trim(params.company))) {
119				flashInsert(error="Required : Company");
120				redirectTo(action="home");
121			}
122			
123			try {
124				local.id = decryptHex(params.id)
125			}
126			catch(Any e) {
127				flash(error="Failed to update company");
128				redirectTo(action="home");
129			}
130			
131			company = model("company").findOne(where="id = #local.id#");
132			
133			company.companyName = params.company;
134			company.address = params.address;
135			company.phone = params.phone;
136			company.fax = params.fax;
137			
138			company.save();
139			
140			flashInsert(info="Successfully edit company");
141			redirectTo(action="home");
142			
143		</cfscript>
144		
145	</cffunction>
146	
147	<cffunction name="deleteCompany" access="public" hint="edit company" description="edit company">
148		
149		<cfscript>
150			
151			if (not StructKeyExists(params, "id")) {
152				flashInsert(error="Failed to delete Company");
153				redirectTo(action="home");
154			}
155			
156			local.id = Right(params.id, Len(params.id) - 3);
157			
158			try {
159				local.id = decryptHex(local.id);
160			}
161			catch(Any e) {
162				flashInsert(error="Failed to delete Company");
163				redirectTo(action="home");
164			}
165			
166			if (not IsNumeric(local.id)) {
167				flashInsert(error="Failed to delete Company");
168				redirectTo(action="home");
169			}
170			
171			company = model("company").deleteAll(where="id = #local.id#");
172			
173			flashInsert(info="Successfully delete company");
174			redirectTo(action="home");
175			
176		</cfscript>
177		
178	</cffunction>
179	
180</cfcomponent>