Exemplo n.º 1
0
        public string GetHtml()
        {
            StringBuilder sb = new StringBuilder();

            if (String.IsNullOrEmpty(FieldName))
            {
                return(Provider.DesignMode ? Provider.GetResource("Select field name") : String.Empty);
            }

            Type                        entityType = Provider.GetEntityType(EntityName);
            Type                        fieldType  = entityType.GetProperty(FieldName).PropertyType;
            PropertyInfo                pi         = entityType.GetProperty(FieldName);
            ColumnDetailAttribute       attrField  = (ColumnDetailAttribute)CMSUtility.GetAttribute(pi, typeof(ColumnDetailAttribute));
            EditFormFieldPropsAttribute attrEdit   = (EditFormFieldPropsAttribute)CMSUtility.GetAttribute(pi, typeof(EditFormFieldPropsAttribute));
            ControlType                 ct         = attrEdit.ControlType;

            if (ct == ControlType.Undefined)
            {
                ct = Provider.GetDefaultControlType(attrField.ColumnType, pi, attrField);
            }

            string label = FieldName.HumanReadable();

            sb.AppendFormat(@"
        <div class=""form-group"">
            <label for=""{0}"" class=""col-sm-4 control-label no-padding-right""> {1} </label>
            <div class=""{3}"">
                {2}
            </div>
        </div>", FieldName, label, GetControlHtml(fieldType, attrField, attrEdit, ct), ct == ControlType.DateTimeEdit ? "col-sm-4 col-xs-6 input-group" : "col-sm-8");

            return(sb.ToString());
        }
Exemplo n.º 2
0
        private string getModuleTypesJSON()
        {
            SortedDictionary <string, ArrayList> grups = new SortedDictionary <string, ArrayList>();

            foreach (Type type in Provider.GetModuleTypes())
            {
                ModuleInfoAttribute mInfo = (ModuleInfoAttribute)CMSUtility.GetAttribute(type, typeof(ModuleInfoAttribute));
                string grup = Provider.GetResource(mInfo.Grup);
                if (!mInfo.Visible)
                {
                    continue;                 //***
                }
                if (!grups.ContainsKey(grup))
                {
                    grups.Add(grup, new ArrayList());
                }
                grups[grup].Add("{name:'" + Provider.GetResource(type.Name) + "',id:'" + type.Name + "'}");
            }
            ArrayList res = new ArrayList();

            foreach (string grup in grups.Keys)
            {
                //grups[grup].Sort();
                res.Add("{grup:'" + grup + "', items:[" + String.Join(",", (string[])grups[grup].ToArray(typeof(string))) + "]}");
            }
            return("[" + String.Join(",", (string[])res.ToArray(typeof(string))) + "]");
        }
Exemplo n.º 3
0
        public override void BeforeSave()
        {
            base.BeforeSave();

            this.Name    = this.Name.Capitalize();
            this.Surname = this.Surname.Capitalize();

            if (this.Nick != null && !Regex.IsMatch(this.Nick, "^[a-zA-Z0-9_]+$"))
            {
                throw new Exception(Provider.TR("Kullanıcı adı sadece harf ve rakamlardan oluşabilir"));
            }

            if (Id == 0)
            {
                //this.Password = Provider.MD5(this.Password); // password işi SetFieldsByPostData'da hallediliyor
                this.Visible = false;
                this.Keyword = CMSUtility.MD5((this.Nick ?? "") + DateTime.Now.Ticks.ToString());

                if (string.IsNullOrWhiteSpace(this.Country) && Provider.Request.UserLanguages != null && Provider.Request.UserLanguages.Length > 0)
                {
                    this.Country = Provider.Request.UserLanguages[0];
                }
            }
            else
            {
                //this.Visible = true; // böyle saçma şey olur mu lan? kim yazmış bunu!
                if (string.IsNullOrWhiteSpace(this.Password))
                {
                    this.Password = Provider.Database.GetString("select Password from User where Id={0}", this.Id);
                }
            }

            downloadPictureForFieldsThatStartsWithHttp();
        }
Exemplo n.º 4
0
        private StringBuilder exportTemplate(string template)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("<template name=\"{0}\">\n", template);
            sb.AppendFormat("\t<code>\n{0}\n\t</code>\n", CMSUtility.HtmlEncode(Provider.Database.GetValue("select HTMLCode from Template where FileName={0}", template).ToString()));
            Module[] modules = Module.Read(template);
            getSerializedModule(sb, modules, "\t");
            sb.Append("</template>\n");
            return(sb);
        }
Exemplo n.º 5
0
        public override List <string> Validate()
        {
            List <string> errorList = base.Validate();
            object        password2 = this["Password2"];

            if (password2 == null || !CMSUtility.MD5(password2.ToString()).Equals(this.Password))
            {
                errorList.Add("Şifreler boş bırakılmamalı ve aynı olmalıdır.");
            }
            return(errorList);
        }
Exemplo n.º 6
0
        private string getEntityTypesJSON()
        {
            ArrayList al = new ArrayList();

            foreach (Type type in Provider.GetEntityTypes())
            {
                ListFormPropsAttribute attr = (ListFormPropsAttribute)CMSUtility.GetAttribute(type, typeof(ListFormPropsAttribute));
                //if (attr.VisibleAtMainMenu)
                al.Add(String.Format("['{0}','{1}',{2}]", type.Name, Provider.GetResource(type.Name), attr.VisibleAtMainMenu.ToJS()));
            }
            //al.Sort();
            return("[" + String.Join(",", (string[])al.ToArray(typeof(string))) + "]");
        }
Exemplo n.º 7
0
        public static string Help([Description("command name to get help")]
                                  string command)
        {
            StringBuilder sb = new StringBuilder();

            if (!String.IsNullOrEmpty(command))
            {
                string methodName = command.Substring(0, 1).ToUpper() + command.Substring(1).ToLower();

                MethodInfo mi = typeof(ConsoleCommands).GetMethod(methodName);
                if (mi == null)
                {
                    throw new Exception("No such command.");
                }

                sb.Append("   usage : " + mi.Name.ToLower());
                StringBuilder sb2 = new StringBuilder();
                foreach (ParameterInfo pi in mi.GetParameters())
                {
                    string desc = (CMSUtility.GetAttribute(pi, typeof(DescriptionAttribute)) as DescriptionAttribute).Description;
                    sb.Append(" <" + pi.Name.ToLower() + ">");
                    sb2.Append("      " + pi.Name.PadRight(15) + " : " + desc + "\n");
                }
                sb.Append("\n" + sb2.ToString());
            }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Command Name");
                dt.Columns.Add("Description");
                foreach (MethodInfo mi in typeof(ConsoleCommands).GetMethods(BindingFlags.Static | BindingFlags.Public))
                {
                    string desc = (CMSUtility.GetAttribute(mi, typeof(DescriptionAttribute)) as DescriptionAttribute).Description;
                    if (!String.IsNullOrEmpty(desc))
                    {
                        DataRow dr = dt.NewRow();
                        dr["Command Name"] = mi.Name.ToLower();
                        dr["Description"]  = desc;
                        dt.Rows.Add(dr);
                    }
                }
                DataRow dr2 = dt.NewRow();
                dr2["Command Name"] = "exit";
                dr2["Description"]  = "exits this window";
                dt.Rows.Add(dr2);

                sb.Append(dt.ToStringTable());
            }
            return(sb.ToString());
        }
Exemplo n.º 8
0
        public override void SetFieldsByPostData(NameValueCollection postData)
        {
            string oldPasswordHash = this.Id > 0 ? Provider.Database.GetString("select [Password] from [User] where Id={0}", this.Id) : this.Password; // eski şifre

            base.SetFieldsByPostData(postData);                                                                                                        // formdan gelen verileri kaydedelim

            if (String.IsNullOrWhiteSpace(this.Password))                                                                                              // eğer formdan gelen şifre boşsa eski şifreyi koruyalım
            {
                this.Password = oldPasswordHash;
            }
            else
            {
                this.Password = CMSUtility.MD5(this.Password);
            }

            this["Password2"] = postData["Password2"];
            HttpPostedFile postedFile = Provider.Request.Files["Avatar"];

            if (postedFile != null && postedFile.ContentLength > 0)
            {
                string avatarDir = Provider.AppSettings["avatarDir"];
                if (String.IsNullOrEmpty(avatarDir))
                {
                    throw new Exception(Provider.GetResource("Avatar folder is not specified in config file."));
                }
                if (!avatarDir.EndsWith("/"))
                {
                    avatarDir += "/";
                }
                string avatarUrlPath = avatarDir + this.Nick.MakeFileName() + DateTime.Now.Millisecond + Path.GetExtension(postedFile.FileName);

                Image bmp = Image.FromStream(Provider.Request.Files["Avatar"].InputStream);
                if (bmp.Width > 240)
                {
                    Image bmp2 = bmp.ScaleImage(240, 0);
                    avatarUrlPath = avatarUrlPath.Substring(0, avatarUrlPath.LastIndexOf('.')) + ".jpg";
                    bmp2.SaveJpeg(Provider.MapPath(avatarUrlPath), Provider.Configuration.ThumbQuality);
                }
                else
                {
                    Provider.Request.Files["Avatar"].SaveAs(Provider.MapPath(avatarUrlPath));
                }


                this.Avatar = avatarUrlPath;

                Provider.DeleteThumbFiles(avatarUrlPath);
            }
        }
Exemplo n.º 9
0
        private List <string> getColumnCategories()
        {
            List <string> res = new List <string>();

            foreach (Column field in Provider.Database.Tables[EntityName].Columns)
            {
                EditFormFieldPropsAttribute attrEdit = (EditFormFieldPropsAttribute)CMSUtility.GetAttribute(Provider.GetEntityType(EntityName).GetProperty(field.Name), typeof(EditFormFieldPropsAttribute));

                if (field.IsPrimaryKey || !attrEdit.Visible)
                {
                    continue; //***
                }
                res.Add(attrEdit.Category);
            }

            return(res.Distinct().ToList());
        }
Exemplo n.º 10
0
        protected void downloadPictureForFieldsThatStartsWithHttp()
        {
            foreach (PropertyInfo pi in this.GetType().GetProperties())
            {
                if (pi.GetSetMethod() == null)
                {
                    continue; //***
                }
                PictureFieldPropsAttribute sp = (PictureFieldPropsAttribute)CMSUtility.GetAttribute(pi, typeof(PictureFieldPropsAttribute));
                if (sp == null || string.IsNullOrEmpty(sp.SpecialFolder) || string.IsNullOrEmpty(sp.SpecialNameField))
                {
                    continue; //***
                }
                string fieldName = pi.Name;
                object val       = pi.GetValue(this, null);

                if (val == null || !(val.ToString().StartsWith("http://") || val.ToString().StartsWith("https://")))
                {
                    continue; //***
                }
                try
                {
                    string specialName = this.GetType().GetProperty(sp.SpecialNameField).GetValue(this, null).ToString();
                    string fileName    = specialName.MakeFileName() + (sp.AddRandomNumber ? "_" + (DateTime.Now.Millisecond % 1000) : "") + val.ToString().Substring(val.ToString().LastIndexOf('.'));
                    if (fileName.Contains("?"))
                    {
                        fileName = fileName.Substring(0, fileName.IndexOf('?'));
                    }
                    string imgFileName = Provider.BuildPath(fileName, sp.SpecialFolder, sp.UseYearMonthDayFolders);

                    WebClient wc = new WebClient();
                    wc.Proxy.Credentials = CredentialCache.DefaultCredentials;
                    wc.DownloadFile(val.ToString(), Provider.MapPath(imgFileName));

                    pi.SetValue(this, imgFileName, null);
                }
                catch (Exception ex)
                {
                    Provider.Log("Notice", "DownloadPicture", ex.Message + "\n (Picture: " + val + ")");
                    pi.SetValue(this, "", null);
                }
            }
        }
Exemplo n.º 11
0
        private void getEntityDocs()
        {
            string entityName = context.Request["entityName"];
            Type   entityType = Provider.GetEntityType(entityName);
            object obj        = Provider.CreateEntity(entityType);

            StringBuilder sb = new StringBuilder();

            sb.Append("<h2>Database Properties</h2>");
            sb.Append("<table>\n");
            sb.AppendFormat("<tr class=\"header\"><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>\n",
                            "Name",
                            "Type",
                            "Declaring Type",
                            "Description",
                            "Default Value");

            int i = 0;

            foreach (PropertyInfo pi in entityType.GetProperties())
            {
                if (!pi.CanWrite)
                {
                    continue;
                }
                if (pi.Name == "Item")
                {
                    continue;
                }

                string caption = Provider.GetResource(pi.DeclaringType.Name + "." + pi.Name);
                if (caption.StartsWith(pi.DeclaringType.Name + ".") && !Provider.DesignMode)
                {
                    caption = pi.Name;
                }
                string description = Provider.GetResource(pi.DeclaringType.Name + "." + pi.Name + "Desc");

                sb.AppendFormat("<tr{5}><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>\n",
                                pi.Name,
                                getShortName(pi.PropertyType),
                                pi.DeclaringType.Name,
                                caption == description ? "" : (caption + ". ") + description,
                                pi.GetValue(obj, null),
                                i % 2 == 0 ? "":" class=\"odd\"");
                i++;
            }
            sb.Append("</table>\n");

            i = 0;
            sb.Append("<h2>Read Only Properties</h2>");
            sb.Append("<table>\n");
            sb.AppendFormat("<tr class=\"header\"><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>\n",
                            "Type",
                            "Name",
                            "Declaring Type",
                            "Description");

            foreach (PropertyInfo pi in entityType.GetProperties())
            {
                if (pi.CanWrite)
                {
                    continue;
                }
                if (pi.Name == "Item")
                {
                    continue;
                }

                DescriptionAttribute desc = pi.GetAttribute <DescriptionAttribute>() ?? new DescriptionAttribute();

                sb.AppendFormat("<tr{4}><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>\n",
                                getShortName(pi.PropertyType),
                                pi.Name,
                                pi.DeclaringType.Name,
                                desc.Description,
                                i % 2 == 0 ? "" : " class=\"odd\"");
                i++;
            }
            sb.Append("</table>\n");

            i = 0;

            sb.Append("<h2>Methods</h2>");
            sb.Append("<table>\n");
            sb.AppendFormat("<tr class=\"header\"><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>\n",
                            "Type",
                            "Name",
                            "Declaring Type",
                            "Description");

            foreach (MethodInfo pi in entityType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                if (pi.IsSpecialName)
                {
                    continue;
                }

                DescriptionAttribute desc = pi.GetAttribute <DescriptionAttribute>() ?? new DescriptionAttribute();

                sb.AppendFormat("<tr{4}><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>\n",
                                getShortName(pi.ReturnType),
                                pi.Name + "(" + pi.GetParameters().Select(p => "<b>" + getShortName(p.ParameterType) + "</b> " + p.Name).StringJoin(", ") + ")",
                                pi.DeclaringType.Name,
                                desc.Description,
                                i % 2 == 0 ? "" : " class=\"odd\"");
                i++;
            }
            sb.Append("</table>\n");

            i = 0;

            if (obj.GetType() != typeof(Lang))
            {
                sb.Append("<h2>Related Entities</h2>");
                sb.Append("<table>\n");
                sb.AppendFormat("<tr class=\"header\"><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>\n",
                                "Entity Name",
                                "Related Field Name",
                                "Label",
                                "Description");
                foreach (Type type in Provider.GetEntityTypes())
                {
                    foreach (PropertyInfo pi in type.GetProperties())
                    {
                        if (pi.DeclaringType == typeof(BaseEntity))
                        {
                            continue;                                         //*** BaseEntity'deki UpdateUserId ve InsertUserId bütün entitilerde var, gereksiz bir ilişki kalabalığı oluşturuyor
                        }
                        ColumnDetailAttribute fda = (ColumnDetailAttribute)CMSUtility.GetAttribute(pi, typeof(ColumnDetailAttribute));
                        if (fda.References == entityType)
                        {
                            sb.AppendFormat("<tr{4}><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>\n",
                                            type.Name,
                                            pi.Name,
                                            Provider.GetResource(type.Name).ToHTMLString(),
                                            Provider.GetResource(type.Name + "Desc").ToHTMLString(),
                                            i % 2 == 0 ? "" : " class=\"odd\"");
                            i++;
                        }
                    }
                }
                sb.Append("</table>\n");
            }

            Provider.Response.Write(sb.ToString());
        }
Exemplo n.º 12
0
 private void getSerializedModule(StringBuilder sb, IEnumerable modules, string tab)
 {
     sb.AppendFormat("{0}<modules>\n", tab);
     foreach (Module mdl in modules)
     {
         sb.AppendFormat("{0}\t<module name=\"{1}\">\n{0}\t\t<serializedData>\n{2}\n{0}\t\t</serializedData>\n", tab, mdl.Name, CMSUtility.HtmlEncode(mdl.Serialize()));
         if (mdl is IRegionContainer)
         {
             List <Module> childModules = (mdl as ModuleContainer).ChildModules;
             getSerializedModule(sb, childModules, tab + "\t");
         }
         sb.AppendFormat("{0}\t</module>\n", tab);
     }
     sb.AppendFormat("{0}</modules>\n", tab);
 }
Exemplo n.º 13
0
        private void importTemplate(string templateData)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(templateData);

            foreach (XmlNode templateNode in doc.SelectNodes("/export/template"))
            {
                string templateName = "";
                if (templateNode != null && templateNode.Attributes["name"] != null && !String.IsNullOrEmpty(templateNode.Attributes["name"].Value))
                {
                    templateName = templateNode.Attributes["name"].Value;
                }
                else
                {
                    throw new Exception(Provider.GetResource("The attribute /template[@name] not found or not valid"));
                }

                string templatePath = Provider.MapPath("/" + templateName);

                XmlNode codeNode = templateNode.SelectSingleNode("code");
                string  code     = "";
                if (codeNode != null && !String.IsNullOrEmpty(codeNode.InnerText))
                {
                    code = CMSUtility.HtmlDecode(codeNode.InnerText.Trim());
                }
                else
                {
                    throw new Exception(Provider.GetResource("The node /template/code not found or not valid"));
                }

                Provider.Database.Begin();

                try
                {
                    // sonra bu template'i ve içindeki modülleri silelim
                    Provider.DeleteTemplate(templateName, false);

                    // yeni template'i oluşturalım
                    Template t = new Template();
                    t.FileName = templateName;
                    t.HTMLCode = code;
                    t.Save();

                    // import edilen modülleri okuyalım
                    List <Module> modules = getModulesFromXML(templateNode.SelectSingleNode("modules"), null);

                    // bu modülleri kaydedelim
                    foreach (Module mdl in modules)
                    {
                        mdl.SaveACopyFor(templateName);
                    }

                    Provider.Database.Commit();
                }
                catch (Exception ex)
                {
                    Provider.Database.Rollback();
                    throw ex;
                }
            }
        }
Exemplo n.º 14
0
        private void getMetadata()
        {
            string entityName = context.Request["entityName"];

            context.Response.Write(CMSUtility.ToJSON(Provider.GetEntityType(entityName)));
        }
Exemplo n.º 15
0
        internal override string show()
        {
            string q = Provider.Request["q"];

            if (q == null)
            {
                q = "";
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("<form id=\"fSearch_{0}\" method=\"get\" action=\"{1}\">", this.Id, this.resultsPage);
            sb.AppendFormat("<input class=\"searchText\" type=\"text\" name=\"q\" value=\"{0}\"/>", CMSUtility.HtmlEncode(q));
            sb.AppendFormat("<span class=\"cbtn cSearchResults\" onClick=\"$('fSearch_{0}').submit();return false;\"></span>", this.Id);
            sb.AppendFormat("</form>");
            return(sb.ToString());
        }
Exemplo n.º 16
0
        private void getGridList()
        {
            string entityName = context.Request["entityName"];

            string where = context.Request["extraFilter"] ?? "";
            string orderBy = context.Request["orderBy"] ?? "";
            string page    = String.IsNullOrEmpty(context.Request["page"]) ? "0" : context.Request["page"];
            string limit   = String.IsNullOrEmpty(context.Request["limit"]) ? "20" : context.Request["limit"];
            int    fieldNo = 0;

            Type       entityType   = Provider.GetEntityType(entityName);
            BaseEntity sampleEntity = Provider.CreateEntity(entityType);

            while (context.Request.Form["f_" + fieldNo] != null)
            {
                string op    = context.Request.Form["o_" + fieldNo];
                string field = context.Request.Form["f_" + fieldNo];
                string val   = context.Request.Form["c_" + fieldNo];
                where += (where == "" ? "" : " AND ") + field + op + val;
                fieldNo++;
            }
            if (!string.IsNullOrWhiteSpace(context.Request.Form["search"]))
            {
                string search = context.Request.Form["search"];
                if (!search.Contains("%"))
                {
                    search = "%" + search + "%";
                }
                where += " AND " + sampleEntity.GetNameColumn() + "like" + search;
            }

            FilterParser filterParser = new FilterParser(where, entityName);

            where = filterParser.GetWhere();

            DataTable dt = Provider.ReadList(entityType, Int32.Parse(page), Int32.Parse(limit), orderBy, where, filterParser.GetParams());

            context.Response.Write("<table class=\"bk-grid\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n");
            if (dt != null)
            {
                context.Response.Write("\t<tr>\n");
                foreach (DataColumn dc in dt.Columns)
                {
                    if (dc.ColumnName == "_CinarRowNumber")
                    {
                        continue;                                     //***
                    }
                    string columnName  = dc.ColumnName;
                    string columnTitle = Provider.TranslateColumnName(entityName, columnName);
                    context.Response.Write("\t\t<th id=\"h_" + dc.ColumnName + "\">" + columnTitle + "</th>\n");
                }
                context.Response.Write("\t</tr>\n");
            }
            if (dt != null)
            {
                if (dt.Rows.Count == 0)
                {
                    context.Response.Write("\t<tr><td style=\"padding:30px;text-align:center\" colspan=\"50\">" + Provider.GetResource("No record") + "</td></tr>\n");
                }
                else
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        context.Response.Write("\t<tr id=\"r_" + dr[0] + "\">\n");
                        foreach (DataColumn dc in dt.Columns)
                        {
                            if (dc.ColumnName == "_CinarRowNumber")
                            {
                                continue;                                     //***
                            }
                            object valObj  = dr[dc.ColumnName];
                            string dispVal = "";
                            if (dr.IsNull(dc))
                            {
                                dispVal = "";
                            }
                            else if (dc.DataType == typeof(Boolean))
                            {
                                dispVal = ((bool)valObj) ? Provider.GetResource("Yes") : Provider.GetResource("No");
                            }
                            else if (dc.DataType == typeof(String))
                            {
                                string str = Regex.Replace(valObj.ToString(), "<.*?>", string.Empty);
                                if (str.Length > 50)
                                {
                                    dispVal = CMSUtility.HtmlEncode(str.StrCrop(50)); // str.Substring(0, 50) + "..."
                                }
                                else
                                {
                                    dispVal = str;
                                }
                            }
                            else if (dc.DataType == typeof(DateTime))
                            {
                                dispVal = ((DateTime)valObj).ToString(Provider.Configuration.DefaultDateFormat);
                            }
                            else
                            {
                                dispVal = valObj.ToString();
                            }
                            context.Response.Write("\t\t<td value=\"" + CMSUtility.HtmlEncode(valObj) + "\">" + dispVal + "</td>\n");
                        }
                        context.Response.Write("\t</tr>\n");
                    }
                }
            }
            context.Response.Write("</table>");
        }
Exemplo n.º 17
0
        public string SendPassword(string email)
        {
            Provider.Database.ExecuteNonQuery("update User set Keyword={0} where Email={1}", CMSUtility.MD5(DateTime.Now.Ticks.ToString()), email);

            User user = (User)Provider.Database.Read(typeof(User), "Email={0}", email);

            if (user == null)
            {
                return(Provider.GetModuleResource("There isn't any user with the email address you entered. Please check."));
            }

            string msg = String.Format(@"
            {0}
            <br/>
            <a href=""http://{1}/LoginWithKeyword.ashx?keyword={2}&rempass=1"">http://{1}/LoginWithKeyword.ashx?keyword={2}&rempass=1</a>", Provider.GetModuleResource("Please change your password by using the address below"), Provider.Configuration.SiteAddress, user.Keyword);

            string res = Provider.SendMail(email, Provider.GetModuleResource("Your Password"), msg);

            if (res == "")
            {
                return(Provider.GetModuleResource("A message sent to your email address. Please read it."));
            }
            else
            {
                return(res);
            }
        }
Exemplo n.º 18
0
        private string generateFormHtml()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"$
var e = new {0}();
var id = int.Parse(Provider.Request.eId ?? ""0"");
if(id>0)
    e = Provider.Database.Read(typeof({0}), id);

if(Provider.Request.cmdName){{
    if(Provider.Request.cmdName==""save"")
    {{
        e.SetFieldsByPostData(Provider.Request.Form);
        e.Save();
        Provider.Response.Redirect(""/{0}View.aspx?eId=""+e.Id);
    }}
}}
$
<script>
    \$(function(){{
        loadForm('#form', $=Utility.ToJSON(e)$, '$=Provider.Request.mode$');
    }});
</script>

<div class=""page-header"">
    <h1>
        {0}
		<small>
			<i class=""icon-double-angle-right""></i>
            $=e.Id > 0 ? 'Edit details' : 'Add new'$
		</small>
	</h1>
</div>

<form id=""form"" method=""post"" action=""$=Provider.Request.RawUrl$"" enctype=""multipart/form-data"" class=""form-horizontal"" role=""form"" autocomplete=""off"">
<input type=""hidden"" name=""cmdName"" value=""save""/>
<input type=""hidden"" name=""Id"" value=""$=e.Id$""/>", EntityName);

            sb.AppendLine();

            int i = 0;

            foreach (var category in getColumnCategories())
            {
                if (i == 0)
                {
                    sb.AppendLine("<div class=\"row\">\r\n<div class=\"col-sm-9\">");
                }
                else if (i == 1)
                {
                    sb.AppendLine(
                        "<div class=\"row\">\r\n<div class=\"col-xs-12 col-sm-6\">\r\n<h3 class=\"header smaller lighter blue\">" +
                        category + "</h3>");
                }
                else
                {
                    sb.AppendLine("<div class=\"col-xs-12 col-sm-6\">\r\n<h3 class=\"header smaller lighter blue\">" + category +
                                  "</h3>");
                }

                foreach (Column field in Provider.Database.Tables[EntityName].Columns)
                {
                    EditFormFieldPropsAttribute attrEdit = (EditFormFieldPropsAttribute)CMSUtility.GetAttribute(Provider.GetEntityType(EntityName).GetProperty(field.Name), typeof(EditFormFieldPropsAttribute));

                    if (field.IsPrimaryKey || !attrEdit.Visible || attrEdit.Category != category)
                    {
                        continue; //***
                    }
                    var ff = new FormField {
                        EntityName = this.EntityName,
                        FieldName  = field.Name
                    };

                    sb.AppendLine(ff.GetHtml());
                }

                if (i == 0)
                {
                    sb.AppendLine(@"
    </div>
    <div class=""col-sm-3"">
	    <img name=""Picture"" class=""img-responsive"" src=""/UserFiles/contact.png"" />
        <input type=""file"" id=""Picture"" name=""Picture"" /><br/>
        $ if(e.Id>0){ $
        <em><i class=""icon-ok green""></i>Added by $=e.InsertUser.FullName$ on $=e.InsertDate.ToString(""dd-MM-yyyy"")$</em>
        $ } $
    </div>
</div>");
                }
                else
                {
                    sb.AppendLine("</div>");
                }

                i++;
            }

            sb.AppendLine(@"

<div class=""clearfix form-actions"">
	<div class=""text-right"">
		<button class=""btn btn-info"" type=""submit"">
			<i class=""icon-ok bigger-110""></i>
			Save
		</button>

		&nbsp; &nbsp; &nbsp;
		<button class=""btn"" type=""button"" onclick=""history.go(-1)"">
			<i class=""icon-undo bigger-110""></i>
			Cancel
		</button>
	</div>
</div>

</form>");

            return(sb.ToString());
        }
Exemplo n.º 19
0
        internal override string show()
        {
            StringBuilder sb = new StringBuilder();

            string thanksMessage = Provider.GetModuleResource("Your message has been sent. Thank you.");

            string errorMessage = "";

            if (Provider.Request["contactUsForm"] == this.Id.ToString())
            {
                Entities.ContactUs contactUs = new Entities.ContactUs();
                contactUs.Email   = Provider.Request["email"];
                contactUs.Message = Provider.Request["message"];
                contactUs.Name    = Provider.Request["name"];
                contactUs.Subject = Provider.Request["subject"];

                try
                {
                    if (Provider.Session["captcha"].ToString() != Provider.Request["capt"])
                    {
                        throw new Exception("Lütfen işlem sonucunu tekrar giriniz.");
                    }

                    contactUs.Save();
                    if (sendMail)
                    {
                        Provider.SendMail(contactUs.Email, contactUs.Name, Provider.Configuration.AuthEmail, Provider.Configuration.SiteName, Provider.GetResource("From visitor: ") + contactUs.Subject, contactUs.Message + "<br/><br/>" + contactUs.Name + "<br/>" + contactUs.Email);
                    }
                    return(thanksMessage);
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message.Replace("\n", "<br/>\n");
                }
            }

            sb.Append("<form action=\"" + Provider.Request.RawUrl + "\" method=\"post\">");
            sb.AppendFormat("<input type=\"hidden\" name=\"contactUsForm\" value=\"{0}\"/>", this.Id);

            if (errorMessage != "")
            {
                sb.AppendFormat("<div class=\"error\">{0}</div>", errorMessage);
            }

            sb.AppendFormat("{0}<br/>", Provider.GetModuleResource("Your Name"));
            sb.AppendFormat("<input class=\"name\" type=\"text\" name=\"name\" value=\"{0}\"/><br/>", CMSUtility.HtmlEncode(Provider.Request["name"]));
            sb.AppendFormat("{0}<br/>", Provider.GetModuleResource("Your Email Address"));
            sb.AppendFormat("<input class=\"email\" type=\"text\" name=\"email\" value=\"{0}\"/><br/><br/>", CMSUtility.HtmlEncode(Provider.Request["email"]));

            sb.AppendFormat("{0}<br/>", Provider.GetModuleResource("Subject"));
            sb.AppendFormat(@"<select class=""subject"" name=""subject"" value=""{0}"">
                <option value="""">{1}</option>
                <option value=""{2}"">{2}</option>
                <option value=""{3}"">{3}</option>
                <option value=""{4}"">{4}</option>
                <option value=""{5}"">{5}</option></select><br/>", CMSUtility.HtmlEncode(Provider.Request["subject"]),
                            Provider.GetResource("Select"),
                            Provider.GetModuleResource("Thank"),
                            Provider.GetModuleResource("Complaint"),
                            Provider.GetModuleResource("Request"),
                            Provider.GetModuleResource("Recommendation"));
            sb.AppendFormat("{0}<br/>", Provider.GetModuleResource("Your Message"));
            sb.AppendFormat("<textarea class=\"message\" name=\"message\">{0}</textarea><br/><br/>", CMSUtility.HtmlEncode(Provider.Request["message"]));

            var r = new Random();
            int a = r.Next(10) + 1;
            int b = r.Next(10) + 1;

            Provider.Session["captcha"] = (a + b).ToString();
            sb.AppendFormat(a + " + " + b + " = ? ");
            sb.AppendFormat("<input class=\"capt\" type=\"text\" name=\"capt\" value=\"\"/><br/>");


            sb.AppendFormat("<input class=\"send\" type=\"submit\" value=\"{0}\"/>", Provider.GetResource("Send"));

            sb.Append("</form>");

            return(sb.ToString());
        }
Exemplo n.º 20
0
        internal override string show()
        {
            StringBuilder sb = new StringBuilder();

            string commentLink   = Provider.GetModuleResource("Comment");
            string emailLink     = Provider.GetModuleResource("Feedback");
            string printLink     = Provider.GetModuleResource("Print");
            string recommendLink = Provider.GetModuleResource("Recommend");

            Entities.Content content = Provider.Content;

            bool     commentsModuleExist = this.ContainerPage == null;
            Comments mdlComments         = null;

            if (this.ContainerPage != null)
            {
                commentsModuleExist = this.ContainerPage.HasModule(typeof(Comments));
                if (commentsModuleExist)
                {
                    mdlComments = (Comments)this.ContainerPage.GetModule(typeof(Comments));
                }
            }

            if (String.IsNullOrEmpty(this.printPage))
            {
                this.printPage = "Print.ashx";
            }

            Hashtable tools = new Hashtable();

            tools["comment"] = (commentsModuleExist || Provider.DesignMode) ? String.Format("<a class=\"comment\" href=\"javascript:{0}\">{1}</a>", mdlComments == null ? "void(0)" : mdlComments.getWriteCommentJS(), getToolHtml(commentIcon, commentLink)) : "";
            tools["email"]   = String.Format("<a class=\"email\" href=\"mailto:{0}?subject={1}\">{2}</a>", Provider.Configuration.AuthEmail, content == null ? "" : CMSUtility.HtmlEncode(content.Title), getToolHtml(emailIcon, emailLink));
            tools["print"]   = content != null?String.Format("<a class=\"print\" href=\"{0}?item={1}\" target=\"_blank\">{2}</a>", printPage, content.Id, getToolHtml(printIcon, printLink)) : "";

            tools["recommendation"] = String.Format("<a class=\"recommend\" href=\"javascript:recommend({0})\">{1}</a>", this.Id, getToolHtml(recommendIcon, recommendLink));

            foreach (string toolName in this.toolOrder.Split(','))
            {
                if (tools.ContainsKey(toolName))
                {
                    sb.Append(tools[toolName]);
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 21
0
        internal override string show()
        {
            StringBuilder sb = new StringBuilder();

            if (String.IsNullOrEmpty(EntityName))
            {
                return(Provider.GetResource("Select entity"));
            }

            Cinar.Database.Table tbl = Provider.Database.Tables[EntityName];
            if (tbl == null)
            {
                return(Provider.GetResource("The table [entityName] coulnd't be found").Replace("[entityName]", EntityName));
            }

            string         pageUrl   = Provider.Request.Url.Scheme + "://" + Provider.Request.Url.Authority + Provider.Request.RawUrl;
            CinarUriParser uriParser = new CinarUriParser(pageUrl);

            if (!String.IsNullOrEmpty(Provider.Request["delete"]))
            {
                deleteEntity();
                uriParser.QueryPart.Remove("delete");
                pageUrl = uriParser.ToString();
            }

            BaseEntity testEntity = Provider.CreateEntity(EntityName);

            if (String.IsNullOrEmpty(ShowFields))
            {
                ShowFields = String.Format("{0},Visible", testEntity.GetNameColumn());
            }

            StringBuilder sbFrom = new StringBuilder();

            sbFrom.AppendFormat("[{0}]\n", EntityName);

            // generate SQL
            string[] showFieldsArr       = ShowFields.Split(',');
            string[] showFieldsArrWithAs = new string[showFieldsArr.Length];
            for (int i = 0; i < showFieldsArr.Length; i++)
            {
                string       field = showFieldsArr[i];
                PropertyInfo pi    = testEntity.GetType().GetProperty(field);
                EditFormFieldPropsAttribute attrib     = (EditFormFieldPropsAttribute)CMSUtility.GetAttribute(pi, typeof(EditFormFieldPropsAttribute));
                ColumnDetailAttribute       fieldProps = (ColumnDetailAttribute)CMSUtility.GetAttribute(pi, typeof(ColumnDetailAttribute));

                string caption = Provider.GetResource(pi.DeclaringType.Name + "." + pi.Name);

                if (fieldProps.References != null)
                {
                    BaseEntity testRefEntity = Provider.CreateEntity(fieldProps.References.Name);
                    showFieldsArrWithAs[i] = "T" + field + "." + testRefEntity.GetNameColumn() + " as [" + caption + "]";

                    sbFrom.AppendFormat("\tleft join [{0}] as {1} ON {1}.{2} = [{3}].{4}\n", fieldProps.References.Name, "T" + field, "Id", EntityName, field);
                }
                else
                {
                    showFieldsArrWithAs[i] = EntityName + "." + field + " as [" + caption + "]";
                }
            }
            ShowFields = String.Join(",", showFieldsArrWithAs);
            ShowFields = EntityName + ".Id," + ShowFields;

            FilterParser filterParser = new FilterParser(this.Filter, EntityName);

            string where = filterParser.GetWhere();

            int pageNo = 0;

            Int32.TryParse(Provider.Request["pageNo"], out pageNo);

            string sql = Provider.Database.AddPagingToSQL(String.Format(@"
                select
                    {0}
                from
                    {1}
                where
                    1=1 {2}
                order by
                    {3} {4}
            ",
                                                                        ShowFields,
                                                                        sbFrom.ToString(),
                                                                        String.IsNullOrEmpty(where) ? "" : ("and " + where),
                                                                        EntityName + "." + this.OrderBy,
                                                                        this.Ascending ? "asc" : "desc"),
                                                          HowManyItems,
                                                          pageNo);

            DataTable dt = Provider.Database.GetDataTable(sql, filterParser.GetParams());

            sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");

            // header
            sb.Append("<tr class=\"header\">\n");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                if (i == 0)
                {
                    continue;
                }
                string colName = dt.Columns[i].ColumnName;
                string img     = "";
                uriParser.QueryPart["orderBy"] = showFieldsArr[i - 1];
                if (this.OrderBy == showFieldsArr[i - 1])
                {
                    uriParser.QueryPart["ascending"] = (!this.Ascending).ToString();
                    img = this.Ascending ? " (asc)" : " (desc)";
                }
                else
                {
                    uriParser.QueryPart["ascending"] = "True";
                }
                sb.AppendFormat("<td><a href=\"{0}\">{1}</a>{2}</td>\n", uriParser.ToString(), colName, img);
            }
            if (this.Editable)
            {
                sb.AppendFormat("<td>{0}</td>\n", "&nbsp;");
            }
            if (this.Deletable)
            {
                sb.AppendFormat("<td>{0}</td>\n", "&nbsp;");
            }
            sb.Append("</tr>\n");

            string nameField = testEntity.GetNameColumn();

            // data
            uriParser = new CinarUriParser(pageUrl);
            foreach (DataRow dr in dt.Rows)
            {
                sb.Append("<tr class=\"data\">\n");
                string editUrl = this.EditPage + "?item=" + dr[0] + "&returnUrl=" + Provider.Server.UrlEncode(Provider.Request.RawUrl);
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }
                    object data = (dr.IsNull(i) || dr[i].Equals("")) ? "&nbsp;" : dr[i];
                    if (showFieldsArr[i - 1] == nameField && this.Editable)
                    {
                        data = "<a href=\"" + editUrl + "\">" + data + "</a>";
                    }
                    if (dr.Table.Columns[i].DataType == typeof(bool))
                    {
                        data = ((bool)data) ? Provider.GetResource("Yes") : Provider.GetResource("No");
                    }
                    sb.AppendFormat("<td>{0}</td>\n", data);
                }
                if (this.Deletable)
                {
                    uriParser.QueryPart["delete"] = dr[0].ToString();
                    sb.AppendFormat("<td><span class=\"cbtn cdelete\" onclick=\"if(confirm('Kayýt silinecek!')) location.href='{0}'\"></span></td>\n", uriParser.ToString());
                }
                if (this.Editable)
                {
                    sb.AppendFormat("<td><span class=\"cbtn cedit\" onclick=\"location.href='{0}'\"></span></td>\n", editUrl);
                }
                sb.Append("</tr>\n");
            }

            // paging
            string prevPageLink = "", nextPageLink = "";

            uriParser = new CinarUriParser(pageUrl);
            if (pageNo > 0)
            {
                uriParser.QueryPart["pageNo"] = (pageNo - 1).ToString();
                prevPageLink = String.Format("<a href=\"{0}\"><< {1}</a>&nbsp;&nbsp;", uriParser.Uri.ToString(), Provider.GetModuleResource("Previous Page"));
            }
            if (dt.Rows.Count == HowManyItems)
            {
                uriParser.QueryPart["pageNo"] = (pageNo + 1).ToString();
                nextPageLink = String.Format("&nbsp;&nbsp;<a href=\"{0}\">{1} >></a>", uriParser.Uri.ToString(), Provider.GetModuleResource("Next Page"));
            }

            sb.AppendFormat("<tr class=\"footer\"><td colspan=\"100\">{0} {1}</td></tr>\n", prevPageLink, nextPageLink);
            sb.Append("</table>\n");

            if (!String.IsNullOrEmpty(NewRecordLink))
            {
                sb.AppendFormat("<p class=\"newRec\"><a href=\"{0}\">{1}</a></p>\n", this.EditPage + "?returnUrl=" + Provider.Server.UrlEncode(Provider.Request.RawUrl), NewRecordLink);
            }

            return(sb.ToString());
        }