Ejemplo n.º 1
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // inizializzazione
        _cmd = master.check_cmd(qry_val("cmd"));

        // elab requests & cmds
        if (this.IsPostBack)
        {
            return;
        }

        try {
            io ob = new io();

            // js request
            if (json_request.there_request(this))
            {
                json_result res = new json_result(json_result.type_result.ok);

                try {
                    json_request jr = new json_request(this);

                    // save_file
                    if (jr.action == "save_file")
                    {
                        synch    s     = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name"));
                        Encoding enc   = System.Text.Encoding.GetEncoding(jr.val_str("enc"));
                        byte[]   bytes = jr.val_bytes("bin_data", enc);
                        string   path  = ob.file_path(jr.val_int("id"));
                        File.WriteAllBytes(path, bytes);
                        s.set_file_content_db(jr.val_int("id"), Path.GetExtension(path).ToLower(), enc.GetString(bytes), DateTime.Now, DateTime.Now);
                    } // synch folders
                    else if (jr.action == "synch_folders")
                    {
                        synch s = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name"));
                        s.synch_event += s_synch_event;
                        synch_results rf = s.reload_folders();
                        res.data     = rf;
                        res.contents = _synch_events;
                    }
                } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); }

                write_response(res);

                return;
            }

            // tasks
            //if(_cmd != null && _cmd.action == "view" && _cmd.obj == "tasks") {
            //  int? fi = qry_val("idt") != "" ? qry_int("idt") : (qry_val("id") != "" ? qry_int("id") : (int?)null)
            //    , sfi = qry_val("sft") != "" ? qry_int("sft") : (qry_val("sf") != "" ? qry_int("sf") : (int?)null);
            //} else throw new Exception("COMANDO NON RICONOSCIUTO!");
        } catch (Exception ex) { log.log_err(ex); if (!json_request.there_request(this))
                                 {
                                     master.err_txt(ex.Message);
                                 }
        }
    }
Ejemplo n.º 2
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // inizializzazione
        _cmd = master.check_cmd(qry_val("cmd"));

        // elab requests & cmds
        if (this.IsPostBack)
        {
            return;
        }

        try {
            users us = new users();

            if (json_request.there_request(this))
            {
                json_result res = new json_result(json_result.type_result.ok);

                try {
                    json_request jr = new json_request(this);

                    // add_user
                    if (jr.action == "add_user")
                    {
                        string user_name = jr.val_str("user_name"), email = jr.val_str("email")
                        , password = jr.val_str("password"), c_password = jr.val_str("c_password");

                        string tkey, akey;
                        us.add_utente(user_name, email, password, c_password, out tkey, out akey, 3);

                        send_mail(email, "conferma iscrizione al dipa notes",
                                  string.Format(@"<h2>{0}.</h2><p>Sei stato iscritto al <a href='{1}'>Deepa-Notes</a>!</p>
                <p><i>Ecco la password: {3}</i></p>
                <h3><a href='{1}confirm.aspx?akey={2}'>entra per confermare la tua iscrizione!</a></h3>"
                                                , user_name, core.base_url, akey, password));
                    } // del_user
                    else if (jr.action == "del_user")
                    {
                        us.del_utente(jr.val_int("id"));
                    } // disable_user
                    else if (jr.action == "disable_user")
                    {
                        us.disable_utente(jr.val_int("id"));
                    } // active_user
                    else if (jr.action == "active_user")
                    {
                        us.riactive_utente(jr.val_int("id"));
                        user u = us.get_user(jr.val_int("id"));

                        send_mail(u.email, "attivazione al deepa-notes",
                                  string.Format(@"<h2>{0}.</h2><pSei stato iscritto al <a href='{1}'>Deepa-Notes</a>!</p>
                <h3><a href='{1}login.aspx?nm={0}'>clicca qui per entrare, ma devi ricordare la password!</a></h3>"
                                                , u.name, core.base_url));
                    }
                } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); }

                write_response(res);

                return;
            }

            // check cmd
            if (_cmd == null)
            {
                return;
            }

            // user
            StringBuilder sb = new StringBuilder();
            if (_cmd.action == "view" && _cmd.obj == "user")
            {
                cmd_add.Value        = master.url_cmd("add user");
                page_title.InnerText = "Utente loggato";
                sb.Append(core.parse_html_block("logged-user", new Dictionary <string, object>()
                {
                    { "us", user }
                }));
                view.InnerHtml = sb.ToString();
            } // users
            else if (_cmd.action == "view" && _cmd.obj == "users")
            {
                cmd_add.Value        = master.url_cmd("add user");
                page_title.InnerText = "Elenco utenti";
                foreach (user u in us.list_users())
                {
                    sb.Append(core.parse_html_block("user", new Dictionary <string, object>()
                    {
                        { "us", u }
                    }));
                }
                view.InnerHtml = sb.ToString();
            } // add user
            else if (_cmd.action == "add" && _cmd.obj == "user")
            {
                cmd_users.Value      = master.url_cmd("view utenti");
                page_title.InnerText = "Nuovo utente";
                view.Visible         = false;
                add.Visible          = true;
            }
            else
            {
                throw new Exception("COMANDO NON RICONOSCIUTO!");
            }
        } catch (Exception ex) { log.log_err(ex); if (!json_request.there_request(this))
                                 {
                                     master.err_txt(ex.Message);
                                 }
        }
    }
Ejemplo n.º 3
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // inizializzazione
        _cmd = master.check_cmd(qry_val("cmd"));

        // elab requests & cmds
        if (this.IsPostBack)
        {
            return;
        }

        try {
            notes ob = new notes();

            // upload file
            if (json_request.there_file(this))
            {
                json_result res = new json_result(json_result.type_result.ok);

                try {
                    if (Request.Files.Count > 0)
                    {
                        HttpFileCollection files = Request.Files;
                        foreach (string key in files)
                        {
                            HttpPostedFile file    = files[key];
                            string         tp_file = key.Split(new char[] { '_' })[0];
                            if (tp_file == "task-file")
                            {
                                int    task_id = int.Parse(key.Split(new char[] { '_' })[2]);
                                byte[] content;
                                using (var streamReader = new MemoryStream()) {
                                    file.InputStream.CopyTo(streamReader);
                                    content = streamReader.ToArray();
                                }
                                add_att(ob, task_id, Path.GetFileName(file.FileName), content);
                            }
                            else
                            {
                                throw new Exception("tipo file upload '" + tp_file + "' non supportato!");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("nessun file da caricare!");
                    }
                } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); }

                write_response(res);

                return;
            }

            // js request
            if (json_request.there_request(this))
            {
                json_result res = new json_result(json_result.type_result.ok);

                try {
                    json_request jr = new json_request(this);

                    // base
                    if (base_elab_action(jr, res))
                    {
                        // fatta
                    }
                    // add_att
                    else if (jr.action == "add_att")
                    {
                        add_att(ob, jr.val_int("task_id"), jr.val_str("name"));
                    }
                    // task_state
                    else if (jr.action == "task_state")
                    {
                        List <free_label> fl = ob.load_free_labels();

                        string folder_path;
                        ob.update_task(jr.val_int("id"), out folder_path, fl, stato: jr.val_str("stato"));
                        List <task_stato> stati = db_conn.dt_table(core.parse_query("menu-states")).Rows.Cast <DataRow>()
                                                  .Select(r => new task_stato(db_provider.str_val(r["stato"]), 0, "", ""
                                                                              , db_provider.str_val(r["title_singolare"]))).ToList();
                        res.html_element = parse_task(ob.load_task(jr.val_int("id")), folder_path, stati);
                    }
                    // set_filter_id
                    else if (jr.action == "set_filter_id")
                    {
                        set_cache_var("active-task-filter", jr.val_str("filter_id"));
                    }
                    // remove_task
                    else if (jr.action == "remove_task")
                    {
                        ob.remove_task(jr.val_int("id"));
                    }
                    // update_task
                    else if (jr.action == "update_task")
                    {
                        List <free_label> fl = ob.load_free_labels();

                        if (!nome_valido(jr.val_str("title")))
                        {
                            throw new Exception("nome '" + jr.val_str("title") + "' non valido!");
                        }

                        string folder_path;
                        ob.update_task(jr.val_int("id"), out folder_path, fl, title: jr.val_str("title"), assegna: jr.val_str("assegna")
                                       , priorita: jr.val_str("priorita"), stima: jr.val_str("stima"), tipo: jr.val_str("tipo"));
                        List <task_stato> stati = db_conn.dt_table(core.parse_query("menu-states")).Rows.Cast <DataRow>()
                                                  .Select(r => new task_stato(db_provider.str_val(r["stato"]), 0, "", ""
                                                                              , db_provider.str_val(r["title_singolare"]))).ToList();
                        res.html_element = parse_task(ob.load_task(jr.val_int("id")), folder_path, stati);
                    }
                    // ren_task
                    else if (jr.action == "ren_task")
                    {
                        if (!nome_valido(jr.val_str("title")))
                        {
                            throw new Exception("nome '" + jr.val_str("title") + "' non valido!");
                        }
                        ob.ren_task(jr.val_int("id"), jr.val_str("title"));
                    }
                    // add_task
                    else if (jr.action == "add_task")
                    {
                        if (!nome_valido(jr.val_str("title")))
                        {
                            throw new Exception("nome '" + jr.val_str("title") + "' non valido!");
                        }

                        ob.add_task(jr.val_int("synch_folder_id"), jr.val_int("folder_id"), jr.val_int_null("search_id"), jr.val_str("stato")
                                    , jr.val_str("title"), jr.val_str("assegna"), jr.val_str("priorita"), jr.val_str("tipo"), jr.val_str("stima"));
                    }
                    // remove_att
                    else if (jr.action == "remove_att")
                    {
                        ob.remove_att(jr.val_int("id"));
                    }
                    // ren_att
                    else if (jr.action == "ren_att")
                    {
                        ob.ren_file(jr.val_int("file_id"), jr.val_str("name"));
                    }
                    // add_folder
                    else if (jr.action == "add_folder")
                    {
                        if (!nome_valido(jr.val_str("title")))
                        {
                            throw new Exception("nome '" + jr.val_str("title") + "' non valido!");
                        }

                        ob.add_folder(jr.val_int("synch_folder_id"), jr.val_int("folder_id"), jr.val_str("title"));
                    }
                    // ren_folder
                    else if (jr.action == "ren_folder")
                    {
                        if (!nome_valido(jr.val_str("title")))
                        {
                            throw new Exception("nome '" + jr.val_str("title") + "' non valido!");
                        }
                        ob.ren_folder(jr.val_int("synch_folder_id"), jr.val_int("folder_id"), jr.val_str("title"));
                    }
                    // del_folder
                    else if (jr.action == "del_folder")
                    {
                        ob.del_folder(jr.val_int("synch_folder_id"), jr.val_int("folder_id"));
                        res.contents = master.url_cmd("tasks");
                    }
                    // cut_element
                    else if (jr.action == "cut_element")
                    {
                        int    f_id = jr.val_int("element_id"), sf_id = jr.val_int("synch_folder_id");
                        string tp = jr.val_str("tp_element"); bool?added = null;
                        if (tp == "folder" || tp == "synch-folder")
                        {
                            if (sf_id > 0 && tp == "synch-folder")
                            {
                                foreach (int id in ob.ids_childs_folders(sf_id))
                                {
                                    added = set_element_cut(id, element_cut.element_cut_type.folder, jr.val_bool("copy")); res.list.Add(id.ToString());
                                }
                            }
                            else
                            {
                                added = set_element_cut(f_id, element_cut.element_cut_type.folder, jr.val_bool("copy")); res.list.Add(f_id.ToString());
                            }
                        }
                        else if (tp == "task")
                        {
                            added = set_element_cut(f_id, element_cut.element_cut_type.task, jr.val_bool("copy"));
                        }
                        else if (tp == "att")
                        {
                            added = set_element_cut(f_id, element_cut.element_cut_type.attachment, jr.val_bool("copy"));
                        }

                        res.set_var("added", added.HasValue ? (added.Value ? "true" : "false") : "none");
                    }
                    // paste_elements
                    else if (jr.action == "paste_elements")
                    {
                        string tp_paste = jr.val_str("tp");
                        int    f_id = jr.val_int("folder_id"), sf_id = jr.val_int("synch_folder_id");
                        bool   paste = false;
                        if (elements_cut.Count > 0)
                        {
                            string err = ""; List <element_cut> ecs = new List <element_cut>();
                            if (tp_paste == "task")
                            {
                                DataRow dr = ob.get_task_info(f_id);
                                if (db_provider.int_val(dr["file_id"]) > 0)
                                {
                                    throw new Exception("questo task non può contenere un allegato!");
                                }
                                string path_task = Path.Combine(db_provider.str_val(dr["synch_local_path"])
                                                                , db_provider.str_val(dr["folder_path"]).Length > 0 ? db_provider.str_val(dr["folder_path"]).Substring(1) : "");
                                foreach (element_cut ec in elements_cut)
                                {
                                    try {
                                        if (ec.tp == element_cut.element_cut_type.attachment)
                                        {
                                            paste = true;
                                            if (!ec.copy)
                                            {
                                                ob.move_file(ec.id, db_provider.int_val(dr["folder_id"]), db_provider.int_val(dr["synch_folder_id"]), path_task);
                                            }
                                            else
                                            {
                                                ob.copy_file(ec.id, db_provider.int_val(dr["folder_id"]), db_provider.int_val(dr["synch_folder_id"]), path_task);
                                            }
                                        }
                                    } catch (Exception ex) {
                                        ecs.Add(ec);
                                        if (err == "")
                                        {
                                            err = ex.Message;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (sf_id <= 0)
                                {
                                    sf_id = ob.get_synch_folder_id(f_id);
                                }
                                foreach (element_cut ec in elements_cut)
                                {
                                    try {
                                        if (ec.tp == element_cut.element_cut_type.folder)
                                        {
                                            ob.move_folder(ec.id, sf_id, f_id > 0 ? f_id : (int?)null); paste = true;
                                        }
                                        else if (ec.tp == element_cut.element_cut_type.task)
                                        {
                                            ob.move_task(ec.id, sf_id, f_id > 0 ? f_id : (int?)null); paste = true;
                                        }
                                    } catch (Exception ex) {
                                        ecs.Add(ec);
                                        if (err == "")
                                        {
                                            err = ex.Message;
                                        }
                                    }
                                }
                            }
                            res.message = err;
                            elements_cut.Clear();
                            foreach (element_cut ec2 in ecs)
                            {
                                elements_cut.Add(ec2);
                            }
                        }

                        if (!paste)
                        {
                            throw new Exception("non è stato incollato nessun elemento!");
                        }
                    }
                    // get_notes
                    else if (jr.action == "get_details")
                    {
                        res.contents = ob.get_task_notes(jr.val_int("task_id"));
                        string html_allegati = "";
                        foreach (DataRow dr in ob.get_task_allegati(jr.val_int("task_id"), jr.val_int_null("search_id")).Rows)
                        {
                            bool cut = there_element_cut(db_provider.int_val(dr["file_id"]), element_cut.element_cut_type.attachment)
                            , found = db_provider.int_val(dr["found_file"]) > 0, file_task = db_provider.int_val(dr["file_task"]) > 0;
                            string style = cut ? "badge-warning" : (found ? "badge-danger" : (file_task ? "badge-primary" : "badge-light"));
                            html_allegati += master.client_key == "" ? core.parse_html_block("task-allegato", new string[, ] {
                                { "file-id", db_provider.str_val(dr["file_id"]) }
                                , { "http-path", db_provider.str_val(dr["http_path"]) }, { "file-name", db_provider.str_val(dr["file_name"]) }, { "style", style }, { "tp_att", style }
                            })
                : core.parse_html_block("task-allegato-client", new string[, ] {
                                { "file-id", db_provider.str_val(dr["file_id"]) }, { "file-name", db_provider.str_val(dr["file_name"]) }, { "style", style }, { "tp_att", style }
                                , { "user-id", ob.user_id.ToString() }, { "user-name", ob.user_name }
                            });
                        }
                        res.html_element = html_allegati != "" ? core.parse_html_block("task-allegati", new string[, ] {
                            { "html-allegati", html_allegati }
                        }) : "";
                    }
                    // save_task_notes
                    else if (jr.action == "save_task_notes")
                    {
                        synch s = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name"));
                        s.save_task_notes(jr.val_int("task_id"), jr.val_str("text"));
                    }
                    else if (jr.action == "synch_folders")
                    {
                        synch s = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name"));
                        s.synch_event += s_synch_event;
                        synch_results rf = s.reload_folders(force: true);
                        res.data     = rf;
                        res.contents = _synch_events;
                    }
                } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); }

                write_response(res);

                return;
            }

            // synch
            if (_cmd != null && _cmd.action == "synch")
            {
                content.InnerHtml = "<p>sincronizzazione cartelle...</p>";
                ClientScript.RegisterStartupScript(GetType(), "__action"
                                                   , "var __action_page = '" + _cmd.action + "';\r\n"
                                                   + "var __user_id = " + this.user.id + ";\r\n"
                                                   + "var __user_name = '" + this.user.name + "';\r\n", true);
            }

            // tasks
            else if (_cmd != null && ((_cmd.action == "view" && _cmd.obj == "tasks") ||
                                      (_cmd.action == "search" && _cmd.obj == "task")))
            {
                int?fi        = qry_val("idt") != "" ? qry_int("idt") : (qry_val("id") != "" ? qry_int("id") : (int?)null)
                , sfi         = qry_val("sft") != "" ? qry_int("sft") : (qry_val("sf") != "" ? qry_int("sf") : (int?)null);
                string search = _cmd.action == "search" ? _cmd.sub_obj() : "";

                // ricerca testo
                int search_cc = 0;
                int?search_id = search != "" ? ob.search_task(search, this.Session.SessionID, out search_cc) : (int?)null;
                search_id_active.Value = search_id.HasValue ? search_id.Value.ToString() : "";

                // filtro attivo
                List <task_filter> tfs = db_conn.dt_table(core.parse_query("filters-tasks")).Rows
                                         .Cast <DataRow>().Select(r => new task_filter(db_provider.int_val(r["task_filter_id"])
                                                                                       , db_provider.str_val(r["filter_title"]), db_provider.str_val(r["filter_notes"])
                                                                                       , db_provider.str_val(r["filter_def"]), db_provider.str_val(r["filter_class"]))).ToList();
                task_filter tf = tfs.FirstOrDefault(x => x.id == int.Parse(get_cache_var("active-task-filter", "1")));
                if (tf == null || search_id.HasValue)
                {
                    tf = new task_filter(0, "elenco completo delle attività", "", "", "");
                }

                ob.load_objects(fi, sfi, tf, search_id);

                menu.InnerHtml  = parse_menu(ob.synch_folders, sfi.HasValue || fi.HasValue, qry_val("cmd"), search_id);
                folder_id.Value = qry_val("id");

                folder       f     = fi.HasValue ? ob.find_folder(fi.Value) : null;
                synch_folder sf    = sfi.HasValue ? ob.find_synch_folder(sfi.Value) : null;
                string       title = f != null ? f.folder_name : (sf != null ? sf.title : "");

                List <task_stato> stati = db_conn.dt_table(core.parse_query("menu-states")).Rows.Cast <DataRow>()
                                          .Select(r => new task_stato(db_provider.str_val(r["stato"]), 0, "", "", db_provider.str_val(r["title_singolare"]))).ToList();

                content.InnerHtml = "<div style='display:none'>virtuale</div>"
                                    + parse_tasks(ob, stati, tf, title, f != null ? ob.find_synch_folder(f.synch_folder_id).title + f.path : "", tfs, search: search_id.HasValue ? search : "");

                ClientScript.RegisterStartupScript(GetType(), "__task_states"
                                                   , "var __action_page = '';\r\n"
                                                   + "var __task_priorita = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-priorita"))) + ";\r\n"
                                                   + "var __task_stime = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-stime"))) + ";\r\n"
                                                   + "var __task_tipi = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-tipi"))) + ";\r\n"
                                                   + "var __task_assegna = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-assegna"))) + ";\r\n"
                                                   + "var __user_id = " + this.user.id + ";\r\n"
                                                   + "var __user_name = '" + this.user.name + "';\r\n", true);
            }
            else
            {
                throw new Exception("COMANDO NON RICONOSCIUTO!");
            }
        } catch (Exception ex) { log.log_err(ex); if (!json_request.there_request(this))
                                 {
                                     master.err_txt(ex.Message);
                                 }
        }
    }